402060: GYM100637 F The Pool for Lucky Ones

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. The Pool for Lucky Onestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A new swimming pool has been built in Kazan for the forthcoming Water Sports World Championship. The pool has N lanes. Some of the lanes are already occupied by swimmers. Tatar scientists have divided the lanes into the lucky and unlucky ones. The unlucky lanes are those with the maximum amount of swimmers. That is, there is no other lane where there would be more swimmers than on unlucky one. The unlucky lanes make swimmers unhappy. The rest of the lanes are considered to be lucky. The lucky lanes make people happy. The scientists took a decision to make more people happy. In order to do this they had an agreement with the pool manager saying they can move a single person from any lane to the one neighboring if it was necessary. The swimmer from the first lane can only be moved to the second lane, and the swimmer from the last lane –– to the one before last.

Input

The first line contains an integer N — the amount of lanes in the pool (3 ≤ N ≤ 105). The second line contains N integers pi separated with spaces, describing distribution of swimmers between the lanes where pi is the amount of swimmers on i-th lane (0 ≤ pi ≤ 105).

Output

Output a single number — minimal possible number of unhappy swimmers.

ExamplesInput
3
1 3 5
Output
5
Input
4
1 0 1 0
Output
2

加入题单

算法标签: