АВТ
Язык:

Дистанционный практикум по программированию

Задачи Online статус Соревнования
Новости Справка СДО
 
Здравствуйте, Гость! Войдите с паролем или зарегистрируйтесь.

887. Игра с шариками

Ограничение времени: 1 сек.
Ограничение памяти:65536 КБайт
Баллы:100
Статистика Послать на проверку Задачу добавил 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

 


Статистика Послать на проверку Обсуждение задачи Автор/источник:
Задачи с соревнований и сборов / Чемпионат мира по программированию (ICPC) / Рыбинск-2010 /
886. A - Спираль 887. 888. C - Числа 889. D - Пузырёк 890. E - Лабиринт.
 
время генерации 0.094 сек.
© Copyright ВоГУ, АВТ, Носов Д.А., Андрианов И.А.