# 129 B



n = int(eval(input()))

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

diff = (100 ** 100)



for t in range(len(l)):

    s1 = 0

    s2 = 0



    for i in range(len(l)):

        if i <= t:

            s1 += l[i]

        else:

            s2 += l[i]

    x = abs(s2 - s1)     

    if x <= diff:

        diff = x 

         

print(diff)

    

n = int(eval(input()))

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

p = [0 for i in range(n)]

p[0] = w[0]

for i in range(1, n):

    p[i] = p[i-1] + w[i]

diff = float('inf')

for j in range(n):

    cd = abs(p[n-1] - (2*p[j]))

    diff = min(diff, cd)

print(diff)
# 129 B
n = int(eval(input()))
l = list(map(int, input().split()))
diff = 100**100
for t in range(len(l)):
    s1 = 0
    s2 = 0
    for i in range(len(l)):
        if i <= t:
            s1 += l[i]
        else:
            s2 += l[i]
    x = abs(s2 - s1)
    if x <= diff:
        diff = x
print(diff)

n = int(eval(input()))
w = list(map(int, input().split()))
p = [0 for i in range(n)]
p[0] = w[0]
for i in range(1, n):
    p[i] = p[i - 1] + w[i]
diff = float("inf")
for j in range(n):
    cd = abs(p[n - 1] - (2 * p[j]))
    diff = min(diff, cd)
print(diff)

-# 129 B -l = list(map(int, input().split())) -diff = 100**100 -for t in range(len(l)): -    s1 = 0 -    s2 = 0 -    for i in range(len(l)): -        if i <= t: -            s1 += l[i] -        else: -            s2 += l[i] -    x = abs(s2 - s1) -    if x <= diff: -        diff = x +w = list(map(int, input().split())) +p = [0 for i in range(n)] +p[0] = w[0] +for i in range(1, n): +    p[i] = p[i - 1] + w[i] +diff = float("inf") +for j in range(n): +    cd = abs(p[n - 1] - (2 * p[j])) +    diff = min(diff, cd)