#P1963. Permutation Transformation
Permutation Transformation
Permutation Transformation
Given N integers \(0, 1, \cdots, N-1\), a transformation sequence \(T\) maps each integer \(i\) to \(T_i\). The sequence \(T\) must satisfy \(\{T_0, T_1, \cdots, T_{N-1}\} = \{0, 1, \cdots, N-1\}\). For any \(x, y \in \{0, 1, \cdots, N-1\}\), the distance between \(x\) and \(y\) is defined as \[ D(x,y)=\min\{|x-y|,\,N-|x-y|\} \] You are given an array of \(N\) integers where the \(i\)-th integer represents \(D(i, T_i)\). Your task is to determine a transformation sequence \(T\) that satisfies these distances. If multiple solutions exist, output the lexicographically smallest one.
inputFormat
The first line contains an integer \(N\) representing the number of integers. The second line contains \(N\) space-separated integers \(d_0, d_1, \ldots, d_{N-1}\) where \(d_i = D(i, T_i)\).
outputFormat
Print a single line containing \(N\) space-separated integers representing the transformation sequence \(T\). If a valid sequence exists, it will be unique under the lexicographical minimality requirement.
sample
3
0 1 1
0 2 1
</p>