CF174C Range Increments
Description
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array $ a $ for all indexes in the segment $ [l,r] $ . In other words, this function does the following:
`
function rangeIncrement(l, r)
for i := l .. r do
a[i] = a[i] + 1
`Polycarpus knows the state of the array $ a $ after a series of function calls. He wants to determine the minimum number of function calls that lead to such state. In addition, he wants to find what function calls are needed in this case. It is guaranteed that the required number of calls does not exceed $ 10^{5} $ . Before calls of function rangeIncrement(l, r) all array elements equal zero.
function rangeIncrement(l, r)
for i := l .. r do
a[i] = a[i] + 1
`Polycarpus knows the state of the array $ a $ after a series of function calls. He wants to determine the minimum number of function calls that lead to such state. In addition, he wants to find what function calls are needed in this case. It is guaranteed that the required number of calls does not exceed $ 10^{5} $ . Before calls of function rangeIncrement(l, r) all array elements equal zero.
Input Format
The first input line contains a single integer $ n $ ( $ 1
Output Format
Print on the first line $ t $ — the minimum number of calls of function rangeIncrement(l, r), that lead to the array from the input data. It is guaranteed that this number will turn out not more than $ 10^{5} $ .
Then print $ t $ lines — the descriptions of function calls, one per line. Each line should contain two integers $ l_{i},r_{i} $ ( $ 1
Explanation/Hint
The first sample requires a call for the entire array, and four additional calls:
- one for the segment \[2,2\] (i.e. the second element of the array),
- three for the segment \[5,5\] (i.e. the fifth element of the array).