Teacher Sorting
InterviewTime limit1sMemory limit512 MB
Given an array, decide whether it can be sorted by disjoint swaps (each index used at most once) and output such a swap sequence.
Problem
The 9th grade students are in Physical Education class, and they have just finished a long-distance run. The lesson is nearing its end, so the teacher asked the students to stand in a line in non-decreasing order of their heights. Students do not always pay attention, so sometimes they stand in a line in an order different from what they were asked. The teacher wants to fix the problem.
The teacher looks at the line, and if it is not ordered properly, chooses the -th and the -th student in the line, and swaps them. After the swap, the -th student becomes the -th student, and the other way around. The teacher keeps doing swaps until the line is ordered properly. Formally speaking, until for all the -th student is not shorter than the -th student in the line.
However, today it will not be easy for the teacher. The students are very tired after the run, so they can hardly stand. The teacher does not want to overload them physically, so the teacher will not move any student more than once.
The teacher needs your help. You are given the line: --- the heights of the students. Find the sequence of swaps for the teacher to make the line ordered properly, or say that it is not possible.
Input
The first line contains an integer --- the number of students ().
The second line contains integers (). The number is the height of the -th student in the line.
Output
If the teacher will not be able to order the students properly, print "No".
Otherwise, print "Yes" in the first line. In the second line print an integer --- the number of swaps the teacher needs to make. In each of the next lines print two integers and , denoting that the teacher should swap the -th and the -th students in the line.
You do not have to minimize the number of swaps. You can print any sequence that will make the line ordered properly in a way that no student was swapped more than once.