#arc129d. [arc129_d]-1+2-1
[arc129_d]-1+2-1
Problem Statement
Given is an integer sequence of length : .
You can repeat the operation below any number of times.
- Choose an integer () and add to , respectively. Here, stands for , and stands for .
Determine whether it is possible to make every element of . If it is possible, find the minimum number of operations needed.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to make every element of , print -1
. If it is possible to do so, print the minimum number of operations needed.
Sample Input 1
4
3 0 -1 -2
Sample Output 1
5
We can achieve the objective in five operations, as follows.
- Do the operation with . Now we have .
- Do the operation with . Now we have .
- Do the operation with . Now we have .
- Do the operation with . Now we have .
- Do the operation with . Now we have .
Sample Input 2
3
1 0 -2
Sample Output 2
-1
Sample Input 3
4
1 -1 1 -1
Sample Output 3
-1
Sample Input 4
10
-28 -3 90 -90 77 49 -31 48 -28 -84
Sample Output 4
962