x = 10**9

n = int(eval(input()))

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

for i in range(n):

    g,t = 0,0

    for j in range(i):

        g+=w[j]

    for k in range(n-i):

        t+=w[n-k-1]

    x = min(x,abs(g-t))

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

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

s,g = sum(a),0

ans = s

for i in a:

    g+=i

    s-=i

    ans = min(ans,abs(s-g))

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

n = int(eval(input()))
a = list(map(int, input().split()))
s, g = sum(a), 0
ans = s
for i in a:
    g += i
    s -= i
    ans = min(ans, abs(s - g))
print(ans)

-x = 10**9 -w = list(map(int, input().split())) -for i in range(n): -    g, t = 0, 0 -    for j in range(i): -        g += w[j] -    for k in range(n - i): -        t += w[n - k - 1] -    x = min(x, abs(g - t)) -print(x) +a = list(map(int, input().split())) +s, g = sum(a), 0 +ans = s +for i in a: +    g += i +    s -= i +    ans = min(ans, abs(s - g)) +print(ans)