#abc116c. [abc116_c]Grand Garden
[abc116_c]Grand Garden
Problem Statement
In a flower bed, there are flowers, numbered . Initially, the heights of all flowers are . You are given a sequence as input. You would like to change the height of Flower to for all , by repeating the following "watering" operation:
- Specify integers and . Increase the height of Flower by for all such that .
Find the minimum number of watering operations required to satisfy the condition.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number of watering operations required to satisfy the condition.
Sample Input 1
4
1 2 2 1
Sample Output 1
2
The minimum number of watering operations required is . One way to achieve it is:
- Perform the operation with .
- Perform the operation with .
Sample Input 2
5
3 1 2 3 1
Sample Output 2
5
Sample Input 3
8
4 23 75 0 23 96 50 100
Sample Output 3
221