Amplifiers
You have a sequence of natural numbers , .
In a continuous subrange of the numbers, let's say from to (where ), you can apply an amplifier. The amplifier increases all the numbers within the range by one, but it can ONLY be used if all these numbers are equal.
Problem
Write a program to calculate the minimum number of amplifiers needed (applied one after the other) to make all numbers in the sequence equal.
Be careful because the number of amplifiers can be very large...
Input File
The first line of the input contains the integer . The second line contains integers , separated by spaces.
Output File
The single line of output should contain only one integer: the minimum number of amplifiers needed to make all numbers in the sequence equal.
Examples of Input - Output Files:
1st
STDIN (amplifiers.in)
3
1 3 2
STDOUT (amplifiers.out)
3
2nd
STDIN (amplifiers.in)
4
1 2 4 2
STDOUT (amplifiers.out)
5
3d
STDIN (amplifiers.in)
5
3 1 4 1 1
STDOUT (amplifiers.out)
6
Constraints
- .
- .
Comments