#P1491G. Switch and Flip
Switch and Flip
No submission language available for this problem.
Description
There are coins labeled from to . Initially, coin is on position and is facing upwards (( is a permutation of numbers from to ). You can do some operations on these coins.
In one operation, you can do the following:
Choose distinct indices and .
Then, swap the coins on positions and .
Then, flip both coins on positions and . (If they are initially faced up, they will be faced down after the operation and vice versa)
Construct a sequence of at most operations such that after performing all these operations the coin will be on position at the end, facing up.
Note that you do not need to minimize the number of operations.
The first line contains an integer () — the number of coins.
The second line contains integers (, for ).
In the first line, output an integer — the number of operations you used.
In the following lines, output two integers and — the positions you chose for the current operation.
Input
The first line contains an integer () — the number of coins.
The second line contains integers (, for ).
Output
In the first line, output an integer — the number of operations you used.
In the following lines, output two integers and — the positions you chose for the current operation.
Samples
Note
Let coin facing upwards be denoted as and coin facing downwards be denoted as .
The series of moves performed in the first sample changes the coins as such:
In the second sample, the coins are already in their correct positions so there is no need to swap.