from sys import stdin

from numpy import cumsum



lines = stdin.readlines



W = [int(i) for i in lines()[1].split()]



total = sum(W)



W = cumsum(W)



ans = 1000000007



for w in W:

    ans = min(ans, abs(total - 2 * w))



print(ans)

N = int(eval(input()))



W = [int(i) for i in input().split()]



total = sum(W)



ans = 1000000007



for i in range(N):

    ans = min(ans, abs(sum(W[:i]) - sum(W[i:])))



print(ans)

from sys import stdin
from numpy import cumsum

lines = stdin.readlines
W = [int(i) for i in lines()[1].split()]
total = sum(W)
W = cumsum(W)
ans = 1000000007
for w in W:
    ans = min(ans, abs(total - 2 * w))
print(ans)

N = int(eval(input()))
W = [int(i) for i in input().split()]
total = sum(W)
ans = 1000000007
for i in range(N):
    ans = min(ans, abs(sum(W[:i]) - sum(W[i:])))
print(ans)

-from sys import stdin -from numpy import cumsum - -lines = stdin.readlines -W = [int(i) for i in lines()[1].split()] +N = int(eval(input())) +W = [int(i) for i in input().split()] -W = cumsum(W) -for w in W: -    ans = min(ans, abs(total - 2 * w)) +for i in range(N): +    ans = min(ans, abs(sum(W[:i]) - sum(W[i:])))