palacinke
On plate are arranged pancakes, one on top of each other. Pancakes are all different sizes, marked with numbers from 1 to n. Small Ðokića must rearrange the pancakes in size, so that the pancake with the number n is on the bottom, and the pancake with number one on top. The only thing he can do is put spatulu under a pancake and turn over all of the pancakes, which are above the spatula (reverse their order, see picture). Help small Ðokića sort the pancakes, so that the number of roll-over is less than 2n. For a solution with multiple roll-ovesr you will not receive points!
Input:
5
2
5
1
3
4
Output:
4
3
2
5
4
Explanation:
4 roll overs have been made,and the results are shown here.
<pre>
2 1 5 4 1
5 5 -> 1 3 2
1 -> 2 2 2 3
3 3 3 1 -> 4
4 4 4 -> 5 5
</pre>
Image: palacinke
InputIn the first line of standard input is a natural number n (1 = n = 5000), which represents the number of pancakes. The following n lines is given a permutation of numbers from 1 to n, in the i-th row is the number a[i] (1 = a [i] = n), which represents the size of the pancake on the i-th place, counting from the top.
OutputTo the standard output print k, the number of roll-overs (0 = k <2n). In each of the following K lines should be one number - the serial number of the pancakes, which is placed under the appropriate spatula (when it determines the serial number, pancakes are counted from the top). If there are more solutions with fewer strokes than 2n, print any solution.
Input:
5
2
5
1
3
4
Output:
4
3
2
5
4
Explanation:
4 roll overs have been made,and the results are shown here.
<pre>
2 1 5 4 1
5 5 -> 1 3 2
1 -> 2 2 2 3
3 3 3 1 -> 4
4 4 4 -> 5 5
</pre>
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.