Tinky Winky left a sequence of
Oh dear! Po, what have you done?! – asked Tinky Winky in horror.
I enhanced the sequence! – replied Po.
After cross-examination, it was established that Po did a number of enhancements on the sequence. In every enhancement, she took a segment of a sequence and increased all elements in the segment by some positive integer. Also, every two segments were either disjoint or one was completely contained in the other.
How many enhancements have you done, Po? – Laa-Laa inquired.
I really don't know! I'm only sure I did the minimum number of enhancements possible to get this sequence! – said Po exhaustedly.
Then it surely must be
What number did Noo-Noo say?
Input Specification
The first line contains an integer
The second line contains
Output Specification
Output
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 30 | |
2 | 40 | No additional constraints. |
Sample Input 1
3
2 2 2
Sample Output 1
1
Sample Input 2
5
2 3 3 3 2
Sample Output 2
2
Explanation for Sample Output 2
Po first increased all elements of the sequence by
Sample Input 3
6
1 2 3 2 1 3
Sample Output 3
4
Comments