N = int(eval(input()))

W = list(map(int,input().split()))

min_w = 10000000

for i in range(N):

  T1 = W[:i]

  T2 = W[i:]

  if min_w > abs(sum(T1)-sum(T2)):

    min_w = abs(sum(T1)-sum(T2))

print(min_w)
N = int(eval(input()))

W = list(map(int,input().split()))

ans = [abs(sum(W[:i])-sum(W[i:])) for i in range(N)]

print((min(ans)))
N = int(eval(input()))
W = list(map(int, input().split()))
min_w = 10000000
for i in range(N):
    T1 = W[:i]
    T2 = W[i:]
    if min_w > abs(sum(T1) - sum(T2)):
        min_w = abs(sum(T1) - sum(T2))
print(min_w)

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

-min_w = 10000000 -for i in range(N): -    T1 = W[:i] -    T2 = W[i:] -    if min_w > abs(sum(T1) - sum(T2)): -        min_w = abs(sum(T1) - sum(T2)) -print(min_w) +ans = [abs(sum(W[:i]) - sum(W[i:])) for i in range(N)] +print((min(ans)))