#Q11. 「一本通 1.1 练习 6」糖果传递
「一本通 1.1 练习 6」糖果传递
Description
Original source: HAOI 2008
There are children sitting in a circle, each with candies. Each child can only pass candies to their immediate left or right neighbors. The cost of passing one candy is . Find the minimum total cost to make all children have an equal number of candies.
Input Format
The first line contains an integer , the number of children;
The next lines each contain an integer .
Output Format
Output the minimum total cost to make all children have an equal number of candies.
Sample 1
4
1
2
5
4
4
Constraints & Hints
For of the data, ;
For of the data, , and it is guaranteed that the answer can be stored in a 64-bit signed integer.