n = int(eval(input()))

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



ans = 10 ** 9

for t in range(n):

    cnt = 0

    for i in range(n):

        a = 1

        if i > t:

            a = -1

        cnt += a * w[i]

    ans = min(ans, abs(cnt))

    

print(ans)
n = int(eval(input()))

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



ans = 10 ** 9

now = sum(w)



for i in range(n):

    now -= 2 * w[i]

    ans = min(ans, abs(now))



print(ans)
n = int(eval(input()))
w = list(map(int, input().split()))
ans = 10**9
for t in range(n):
    cnt = 0
    for i in range(n):
        a = 1
        if i > t:
            a = -1
        cnt += a * w[i]
    ans = min(ans, abs(cnt))
print(ans)

n = int(eval(input()))
w = list(map(int, input().split()))
ans = 10**9
now = sum(w)
for i in range(n):
    now -= 2 * w[i]
    ans = min(ans, abs(now))
print(ans)

-for t in range(n): -    cnt = 0 -    for i in range(n): -        a = 1 -        if i > t: -            a = -1 -        cnt += a * w[i] -    ans = min(ans, abs(cnt)) +now = sum(w) +for i in range(n): +    now -= 2 * w[i] +    ans = min(ans, abs(now))