There are n coins marked from 1 to n. At first, coin ci is on position I and is confronting upwards ((c1,c2,… ,cn) is a change of numbers from 1 to n). You can do a few procedure on these coins. In one activity, you can do the accompanying: Pick 2 particular records I and j. Then, at that point, trade the coins on positions I and j.
Correct answer will be upvoted else downvoted. Computer science.
There are n coins marked from 1 to n. At first, coin ci is on position I and is confronting upwards ((c1,c2,… ,cn) is a change of numbers from 1 to n). You can do a few procedure on these coins.
In one activity, you can do the accompanying:
Pick 2 particular records I and j.
Then, at that point, trade the coins on positions I and j.
Then, at that point, flip the two coins on positions I and j. (In case they are at first looked up, they will be looked down after the activity as well as the other way around)
Build a grouping of all things considered n+1 activities with the end goal that subsequent to playing out this load of tasks the coin I will be on position I toward the end, looking up.
Note that you don't have to limit the number of activities.
Input
The principal line contains an integer n (3≤n≤2⋅105) — the number of coins.
The subsequent line contains n integers c1,c2,… ,cn (1≤ci≤n, ci≠cj for i≠j).
Output
In the principal line, output an integer q (0≤q≤n+1) — the number of activities you utilized.
In the accompanying q lines, output two integers I and j (1≤i,j≤n,i≠j) — the positions you decided for the current activity
Step by step
Solved in 3 steps with 1 images