Adrenaline Rush
Alice’s friend is a big fan of the Adrenaline Rush racing competition and always strives to attend every race. However, this time, Alice is the one watching the race. To ensure her friend does not miss any important details, Alice decides to take notes on everything that happens on the track.
The first thing Alice notices before the race begins is the numbering of the cars. All the cars line up in front of the starting line in a specific order. The car closest to the line is numbered , the second car is numbered , and so on, up to the last car, which is numbered .
The race begins with the countdown: "Three! Two! One! Go!". Alice observes that the cars start in their original order. However, as the race progresses, their order changes. She records whenever one car overtakes another, essentially swapping places with it on the track.
During the race, Alice notices something curious: no car overtakes another more than once. In other words, for any two cars and , there can be at most two overtakes between them during the race: " overtakes " and/or " overtakes ".
At the end of the race, Alice carefully writes down the final order of the cars , where represents the winner of the race.
Alice’s friend, however, is only interested in the final ranking and discards all of Alice’s notes except for the final ordering. As Alice is quite curious, she wonders: What is the maximum possible number of overtakes she could have observed during the race? Your task is to help Alice answer this question.
Input
The first line of the input contains a single integer () — the number of cars in the race.
The second line contains a permutation (, ) — the final order of the cars from 1st to -th place.
Output
The first line should contain a single integer — the maximum possible number of overtakes.
Each of the next lines should contain two integers and (), representing an overtake event where car overtakes car . This means car was directly behind car and passes it.
If there are multiple maximum-length valid overtake sequences, output any of them.
Notes
Two cars can swap places only if they are currently adjacent on the track.
No ordered pair of cars can occur as an overtake more than once (i.e., car cannot overtake car a second time).