You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.

### Question:
There are N boxes in a row, numbered 1 to N. Box i contains A_i balls. You may perform the following operation any number of times: choose two adjacent boxes and move one ball from one of them to the other.
Find the minimum number of operations needed so that every box contains the same number of balls, or print -1 if it is impossible.

Input

The input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N

Output

Print the answer.

Constraints

1 <= N <= 2 * 10^5
0 <= A_i <= 10^9
All input values are integers.

Sample Input 1

3
1 2 6

Sample Output 1

5

Sample Input 2

2
1 2

Sample Output 2

-1

### Format: Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within delimiters as follows. Ensure that when the python program runs, it reads the inputs, runs the algorithm and writes output to STDOUT.
```python
# YOUR CODE HERE
```

### Answer: (use the provided format with backticks)

