#abc129b. [abc129_b]Balance
[abc129_b]Balance
Problem Statement
We have weights indexed to . The mass of the weight indexed is .
We will divide these weights into two groups: the weights with indices not greater than , and those with indices greater than , for some integer . Let be the sum of the masses of the weights in the former group, and be the sum of the masses of the weights in the latter group.
Consider all possible such divisions and find the minimum possible absolute difference of and .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible absolute difference of and .
Sample Input 1
3
1 2 3
Sample Output 1
0
If , and , with the absolute difference of .
Sample Input 2
4
1 3 1 1
Sample Output 2
2
If , and , with the absolute difference of . We cannot have a smaller absolute difference.
Sample Input 3
8
27 23 76 2 3 5 62 52
Sample Output 3
2