Problem Statement
We have a permutation P=P0,P1,ldots,PN−1 of 0,1,ldots,N−1.
You can do the following operation on P at most 2times105 times:
- Announce an integer i (0leqileqN−1). Swap Pi and P(i+Pi)textrmmodN.
Your task is to sort P in ascending order with this operation. If it is impossible, print -1
instead.
Constraints
- All values in input are integers.
- 2leqNleq100
- P is a permutation of 0,1,ldots,N−1.
Input is given from Standard Input in the following format:
N
P0 P1 ldots PN−1
Output
If it is impossible to sort P in ascending order with at most 2times105 operations, print -1
.
Otherwise, print K+1 lines to represent a sequence of operations that sorts P in ascending order, where K is the number of operations done, as follows:
- The first line should contain the integer K;
- the (1+i)-the line (1leqileqK) should contain the integer j (0leqjleqN−1) announced in the i-th operation.
You do not have to minimize the number of operations done. If there are multiple such sequences of at most 2times105 operations, any of them will be accepted.
8
7 1 2 6 4 0 5 3
Sample Output 1
4
6
0
3
0
This sequence of operations sorts P in ascending order, as follows:
-
First, announce i=6. We swap P6(=5) and P(6+5)textrmmod8=P3(=6), turning P into 7,1,2,5,4,0,6,3.
-
Then, announce i=0. We swap P0(=7) and P(0+7)textrmmod8=P7(=3), turning P into 3,1,2,5,4,0,6,7.
-
Then, announce i=3. We swap P3(=5) and P(3+5)textrmmod8=P0(=3), turning P into 5,1,2,3,4,0,6,7.
-
Finally, announce i=0. We swap P0(=5) and P(0+5)textrmmod8=P5(=0), turning P into 0,1,2,3,4,5,6,7.