PROGRAMMING:Candy for military training
Every year, new students will have military training. As a senior and elder student, they have also experienced military training. They had experienced that they were very thirsty during military training, while the seniors and sisters were eating watermelon. So the seniors and sisters want you to experience what they used to feel. You know the moves of elder and elder students in advance. So when you go to military training every day, you will bring some candy. When you come to eat watermelon, you will resist temptation by eating sugar.
Now you have n people sitting in a circle, each with a [i] candy. Because each of you has different candy, you will pass candy to make everyone's candy the same. But each person can only pass candy to the left and right. It costs 1 to pass one candy each time. The minimum cost of equal candy for all.
###Input format:
In the first line, enter a positive integer n to represent the number of people (1 ≤ n ≤ 1000000).
In the second line, n integers a [i] represent the initial number of candies obtained by the i-th person.
###Output format:
Output an integer to represent the minimum cost.
###Input example:
```in
four
1 2 5 4
```
###Output example:
```out
four
```
answer:If there is no answer, please comment
Now you have n people sitting in a circle, each with a [i] candy. Because each of you has different candy, you will pass candy to make everyone's candy the same. But each person can only pass candy to the left and right. It costs 1 to pass one candy each time. The minimum cost of equal candy for all.
###Input format:
In the first line, enter a positive integer n to represent the number of people (1 ≤ n ≤ 1000000).
In the second line, n integers a [i] represent the initial number of candies obtained by the i-th person.
###Output format:
Output an integer to represent the minimum cost.
###Input example:
```in
four
1 2 5 4
```
###Output example:
```out
four
```
answer:If there is no answer, please comment