#P1963. [NOI2009] 变换序列

[NOI2009] 变换序列

Description

Consider the integers 0,1,,N10, 1, \cdots, N-1. A transformation sequence TT maps ii to TiT_i, where Ti{0,1,,N1}T_i \in \{ 0,1,\cdots, N-1\} and i=0N1{Ti}={0,1,,N1}\bigcup_{i=0}^{N-1} \{T_i\} = \{0,1,\cdots , N-1\}. For all x,y{0,1,,N1}x, y \in \{0,1,\cdots , N-1\}, define the distance between xx and yy as D(x,y)=min{xy,Nxy}D(x,y)=\min\{|x-y|,N-|x-y|\}. Given each D(i,Ti)D(i,T_i), you need to find a transformation sequence TT that satisfies the requirements. If there are multiple valid sequences, output the lexicographically smallest one.

Note: For two transformation sequences SS and TT, if there exists p<Np < N such that for i=0,1,,p1i = 0, 1, \cdots, p-1, Si=TiS_i = T_i and Sp<TpS_p < T_p, then we say SS is lexicographically smaller than TT.

Input Format

The first line contains a positive integer NN, the length of the sequence. The next line contains NN integers DiD_i, where DiD_i denotes the distance between ii and TiT_i.

Output Format

If at least one valid transformation sequence TT exists, output one line with NN integers, which is the lexicographically smallest TT you computed; otherwise output No Answer. Note that adjacent numbers are separated by a single space, and there is no trailing space at the end of the line.

5
1 1 2 2 1

1 2 4 0 3

Hint

  • For 30% of the testdata: N50N \le 50.
  • For 60% of the testdata: N500N \le 500.
  • For 100% of the testdata: N104N \le 10^4.

Translated by ChatGPT 5