ÀÂÒ
Language: Russian
English

Remote Training on Programming

Problems Online status Contests
News FAQ E-learning
For authors:
Register  ||  Login
 
Hello, Guest! Please login or register.

887. Beads game

Time Limit: 1 seconds
Memory Limit:65536KB
Points:100
View Problem Statistics Submit Problem added debug

There are n boxes in a row. Each box contains Ki beads. It is known that the total number of beads is a multiple of n. On each move a single bead can be moved from its box to an adjacent box (to the left or to the right). Obviously, there exists a sequence of moves that will result in the same number of beads in each box.

Write a program to determine the minimum number of moves leading to equal number of beads in all boxes.

Limitations

1 <= n <= 100 000;            0 <= Ki <= 100 000.

Input

The first line contains an integer n. The following line contain numbers Ki.

Output

The output file must specify a single integer, the minimum possible number of moves leading to equal number of beads in all boxes.

Sample

Standard input

Standard output

5

4 1 3 2 5

5

 


View Problem Statistics Submit Problem discussion Author/source:
Problems from Contests and Camps / World Championship in Programming (ICPC) / Rybinsk-2010 /
886. A - Spiral 887. 888. C - Numbers 889. D - Bubble 890. E - Maze
time generating 0.375 sec.
© Copyright VSU, AVT, Nosov D.A., Andrianov I.A.