100 atcoder#ABC129B. [ABC129B] Balance

[ABC129B] Balance

Score : 200200 points

Problem Statement

We have NN weights indexed 11 to NN. The mass of the weight indexed ii is WiW_i.

We will divide these weights into two groups: the weights with indices not greater than TT, and those with indices greater than TT, for some integer 1T<N1 \leq T < N. Let S1S_1 be the sum of the masses of the weights in the former group, and S2S_2 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 S1S_1 and S2S_2.

Constraints

  • 2N1002 \leq N \leq 100
  • 1Wi1001 \leq W_i \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

W1W_1 W2W_2 ...... WN1W_{N-1} WNW_N

Output

Print the minimum possible absolute difference of S1S_1 and S2S_2.

3
1 2 3
0

If T=2T = 2, S1=1+2=3S_1 = 1 + 2 = 3 and S2=3S_2 = 3, with the absolute difference of 00.

4
1 3 1 1
2

If T=2T = 2, S1=1+3=4S_1 = 1 + 3 = 4 and S2=1+1=2S_2 = 1 + 1 = 2, with the absolute difference of 22. We cannot have a smaller absolute difference.

8
27 23 76 2 3 5 62 52
2