Score : $500$ points
We have a permutation $P = P_1, P_2, \ldots, P_N$ of $1, 2, \ldots, N$.
You have to do the following $N - 1$ operations on $P$, each exactly once, in some order:
Swap $P_1$ and $P_2$.
Swap $P_2$ and $P_3$.
$\vdots$
Swap $P_{N-1}$ and $P_N$.
Your task is to sort $P$ in ascending order by configuring the order of operations.
If it is impossible, print -1
instead.
Input is given from Standard Input in the following format:
$N$ $P_1$ $P_2$ $\ldots$ $P_N$
If it is impossible to sort $P$ in ascending order by configuring the order of operations, print -1
.
Otherwise, print $N-1$ lines to represent a sequence of operations that sorts $P$ in ascending order. The $i$-th line $(1 \leq i \leq N - 1)$ should contain $j$, where the $i$-th operation swaps $P_j$ and $P_{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 $P$ in ascending order:
5 5 4 3 2 1
-1