#arc136c. [arc136_c]Circular Addition
[arc136_c]Circular Addition
Problem Statement
We have an integer sequence of length : (note that its index is -based). Initially, all elements of are .
You can repeat the following operation any number of times.
- Choose integers (, ). Then, for every such that , increase the value of by .
You are given an integer sequence of length : . Find the minimum number of operations needed to make equal .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
1 2 1 2
Sample Output 1
2
We should do the following.
- Initially, we have .
- Do the operation with , making .
- Do the operation with , making .
Sample Input 2
5
3 1 4 1 5
Sample Output 2
7
Sample Input 3
1
1000000000
Sample Output 3
1000000000