atcoder#ARC110C. [ARC110C] Exoswap
[ARC110C] Exoswap
Score : points
Problem Statement
We have a permutation of .
You have to do the following operations on , each exactly once, in some order:
- Swap and .
- Swap and .
- Swap and .
Your task is to sort in ascending order by configuring the order of operations.
If it is impossible, print -1
instead.
Constraints
- All values in input are integers.
- is a permutation of .
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to sort in ascending order by configuring the order of operations, print -1
.
Otherwise, print lines to represent a sequence of operations that sorts in ascending order. The -th line should contain , where the -th operation swaps and .
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 in ascending order:
- First, swap and , turning into .
- Then, swap and , turning into .
- Then, swap and , turning into .
- Finally, swap and , turning into .
5
5 4 3 2 1
-1