atcoder#ARC110C. [ARC110C] Exoswap

[ARC110C] Exoswap

Score : 500500 points

Problem Statement

We have a permutation P=P1,P2,,PNP = P_1, P_2, \ldots, P_N of 1,2,,N1, 2, \ldots, N.

You have to do the following N1N - 1 operations on PP, each exactly once, in some order:

  • Swap P1P_1 and P2P_2.
  • Swap P2P_2 and P3P_3. \vdots
  • Swap PN1P_{N-1} and PNP_N.

Your task is to sort PP in ascending order by configuring the order of operations. If it is impossible, print -1 instead.

Constraints

  • All values in input are integers.
  • 2N2×1052 \leq N \leq 2 \times 10^5
  • PP is a permutation of 1,2,,N1, 2, \ldots, N.

Input

Input is given from Standard Input in the following format:

NN

P1P_1 P2P_2 \ldots PNP_N

Output

If it is impossible to sort PP in ascending order by configuring the order of operations, print -1.

Otherwise, print N1N-1 lines to represent a sequence of operations that sorts PP in ascending order. The ii-th line (1iN1)(1 \leq i \leq N - 1) should contain jj, where the ii-th operation swaps PjP_j and Pj+1P_{j + 1}.

If there are multiple such sequences of operations, any of them will be accepted.

5
2 4 1 5 3
4
2
3
1

The following sequence of operations sort PP in ascending order:

  • First, swap P4P_4 and P5P_5, turning PP into 2,4,1,3,52, 4, 1, 3, 5.
  • Then, swap P2P_2 and P3P_3, turning PP into 2,1,4,3,52, 1, 4, 3, 5.
  • Then, swap P3P_3 and P4P_4, turning PP into 2,1,3,4,52, 1, 3, 4, 5.
  • Finally, swap P1P_1 and P2P_2, turning PP into 1,2,3,4,51, 2, 3, 4, 5.
5
5 4 3 2 1
-1