#P8880. Permutation Sum Modulo
Permutation Sum Modulo
Permutation Sum Modulo
Naxida has a permutation (c) of numbers from (0) to (n-1). She wants you to construct two permutations (a) and (b) of the same set ({0, 1, \ldots, n-1}) such that for every index (i) (where indices are considered from (0) to (n-1) for implementation purposes), the following equation holds: [ c_i = (a_i + b_i) \mod n ] If it is impossible to meet Naxida's requirement, output (-1).
Note: It can be shown that a solution exists if and only if (n) is odd. When (n) is even, output (-1). When (n) is odd, one valid construction is to set [ a_i = (2 \times c_i) \mod n, \quad b_i = (- c_i) \mod n. ] This works because for odd (n) the multiplication by 2 and by (-1) are bijections on ({0, \ldots, n-1}).
inputFormat
The first line contains a single integer (n) representing the size of the permutation. The second line contains (n) space-separated integers representing the permutation (c) of ({0, 1, \ldots, n-1}).
outputFormat
If there exists a valid pair of permutations (a) and (b), output two lines: the first line is the permutation (a) and the second line is the permutation (b), both space-separated. If no valid pair exists, output a single line with (-1).
sample
3
1 0 2
2 0 1
2 0 1
</p>