#P3584. [POI 2015 R1] 贪吃鬼 Gluttons

[POI 2015 R1] 贪吃鬼 Gluttons

Description

There are nn dishes placed around a round table, forming a circle. The ii-th dish contains cic_i calories. Between every pair of adjacent dishes sits one person, so there are nn people in total. Each person can choose to eat either the dish on their left or the dish on their right. If two people choose the same dish, they split it equally, and each receives half of that dish’s calories. If a person can obtain strictly more calories than before by changing only their own choice (while the choices of the other n1n-1 people remain unchanged), then that person is dissatisfied. Please assign which dish each person should eat so that everyone is satisfied.

Input Format

The first line contains an integer nn, the number of dishes (which is also the number of people; both dishes and people are numbered from 11 to nn).
The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n. We stipulate that for person ii (1i<n1 \le i < n), the dish on the left is dish ii, and the dish on the right is dish i+1i+1; for person nn, the dish on the left is dish nn, and the dish on the right is dish 11.

Output Format

If no such assignment exists, output a single line NIE.
If such an assignment exists, output one line with nn integers, where the ii-th integer is the index of the dish chosen by person ii. If multiple valid assignments exist, output any one of them.

5
5 3 7 2 9

2 3 3 5 1

Hint

Constraints

For all testdata, 2n1062 \leqslant n \leqslant 10^6, 1ci1091 \leqslant c_i \leqslant 10^9.


Original title: Łasuchy.

Thanks to @KSkun for providing the SPJ for this problem.

Translated by ChatGPT 5