N = int(eval(input()))

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

l = []

for T in range(N):

    sum1 = sum(W[:T+1])

    sum2 = sum(W[T+1:])

    d = abs(sum1-sum2)

    l.append(d)

print((min(l)))
N = int(eval(input()))

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

l = []

for T in range(N):

    sum1 = sum(W[:T])

    sum2 = sum(W[T:])

    d = abs(sum1-sum2)

    l.append(d)

print((min(l)))
N = int(eval(input()))
W = list(map(int, input().split()))
l = []
for T in range(N):
    sum1 = sum(W[: T + 1])
    sum2 = sum(W[T + 1 :])
    d = abs(sum1 - sum2)
    l.append(d)
print((min(l)))

N = int(eval(input()))
W = list(map(int, input().split()))
l = []
for T in range(N):
    sum1 = sum(W[:T])
    sum2 = sum(W[T:])
    d = abs(sum1 - sum2)
    l.append(d)
print((min(l)))

-    sum1 = sum(W[: T + 1]) -    sum2 = sum(W[T + 1 :]) +    sum1 = sum(W[:T]) +    sum2 = sum(W[T:])