n = int(eval(input()))

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

ans = 10000000000

for t in range(1, n):

    left, right = 0, 0

    for i in range(t):

        left += w[i]

    for i in range(t, n):

        right += w[i]

    ans = min(ans, abs(left - right))

print(ans)

n = int(eval(input()))

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

ans = 10000000000

for t in range(1, n):

    left = sum(w[:t])

    right = sum(w[t:])

    ans = min(ans, abs(left - right))

print(ans)

n = int(eval(input()))
w = list(map(int, input().split()))
ans = 10000000000
for t in range(1, n):
    left, right = 0, 0
    for i in range(t):
        left += w[i]
    for i in range(t, n):
        right += w[i]
    ans = min(ans, abs(left - right))
print(ans)

n = int(eval(input()))
w = list(map(int, input().split()))
ans = 10000000000
for t in range(1, n):
    left = sum(w[:t])
    right = sum(w[t:])
    ans = min(ans, abs(left - right))
print(ans)

-    left, right = 0, 0 -    for i in range(t): -        left += w[i] -    for i in range(t, n): -        right += w[i] +    left = sum(w[:t]) +    right = sum(w[t:])