- Time limit: 1.00 s
- Memory limit: 512 MB
You have an array that contains a permutation of integers . Your task is to sort the array in increasing order by reversing subarrays. You can construct any solution that has at most reversals.
Input
The first input line has an integer : the size of the array. The array elements are numbered .
The next line has integers : the contents of the array.
Output
First print an integer : the number of reversals.
After that, print lines that describe the reversals. Each line has two integers and : you reverse a subarray from position to position .
Constraints
Example
Input:
4 2 3 1 4
Output:
2 1 3 2 3