#P2512. [HAOI2008] 糖果传递

[HAOI2008] 糖果传递

Description

There are nn children sitting in a circle, each with aia_i candies. Each child can only pass candies to their left and right neighbors. The cost of passing one candy each time is 11.

Input Format

The first line contains nn. Each of the next nn lines contains aia_i.

Output Format

Output the minimum cost to make all children have the same number of candies.

4
1
2
5
4
4

Hint

Constraints: For 100%100\% of the testdata, 1n1061 \le n \le 10^6, 1ai1.5×1091 \le a_i \le 1.5 \times 10^9, and i=1nai\sum_{i=1}^{n}{a_i} is a multiple of nn.

Translated by ChatGPT 5