N = int(eval(input()))

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



ans = 999999



for i in range(N):

    f = l[:i]

    s = l[i:]

    diff = abs(sum(f)-sum(s))

    if diff <= ans:

        ans = diff

    

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



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



ans = 100*1000



for i in range(N):

    f = sum(weights[:i])

    s = sum(weights[i:])

    dif = abs(f-s)

    

    if dif < ans:

        ans = dif

        

print(ans)
N = int(eval(input()))
l = list(map(int, input().split()))
ans = 999999
for i in range(N):
    f = l[:i]
    s = l[i:]
    diff = abs(sum(f) - sum(s))
    if diff <= ans:
        ans = diff
print(ans)

N = int(eval(input()))
weights = list(map(int, input().split()))
ans = 100 * 1000
for i in range(N):
    f = sum(weights[:i])
    s = sum(weights[i:])
    dif = abs(f - s)
    if dif < ans:
        ans = dif
print(ans)

-l = list(map(int, input().split())) -ans = 999999 +weights = list(map(int, input().split())) +ans = 100 * 1000 -    f = l[:i] -    s = l[i:] -    diff = abs(sum(f) - sum(s)) -    if diff <= ans: -        ans = diff +    f = sum(weights[:i]) +    s = sum(weights[i:]) +    dif = abs(f - s) +    if dif < ans: +        ans = dif