Builder
In a street, there are N adjacent buildings, the i-th building (from left to right) has (a_i) floors. A builder has come up with a way to adjust the heights of the buildings so that they all have the same number of floors, by performing a series of phases.
According to the rules defined by the Brazilian Society of Construction (SBC), each time the builder increases a building's height, all adjacent buildings that have the same number of floors should also be increased by 1 floor.
For example, suppose (N) is equal to 8, where the initial heights are (a_1 = 5, a_2 = 4, a_3 = 4, a_4 = 4, a_5 = 5, a_6 = 4, a_7 = 4, a_8 = 7).
- The builder can define (L = 2) and (R = 3) for the first phase, so that all heights at the end will be: (5, 4, 4, 4, 6, 4, 4, 7).
- The builder can then define (L = 2) and (R = 4) for the second phase, so that the heights will finally be: (5, 5, 5, 5, 6, 4, 4, 7).
To complete the work, the builder wants to minimize the number of phases needed. In the example mentioned, how can you achieve this?
The goal is to determine the minimum number of phases required to complete the construction.
Input
The first line of the input contains a single integer (N) (the number of buildings in the street).
The second line contains (N) integers, where the i-th integer (a_i) is the number of floors of the i-th building.
Output
The output should contain a single integer, the minimum number of phases needed to complete the work.
Constraints
- (2 \leq N \leq 100)
- (1 \leq a_i \leq 100)
Examples
Example Input 1
4
3 1 1 2
Example Output 1
2
Example Input 2
8
5 4 4 4 5 4 4 7
Example Output 2
4
Example Input 3
3
100 100 100
Example Output 3
0