n,*w=list(map(int,open(0).read().split()))



min_val=None

for i in range(n-1):

  y=abs(sum(w[:i+1]) - sum(w[i+1:]))

  if min_val is None or y < min_val:

    min_val = y

print(min_val)
n,*w=list(map(int,open(0).read().split()))



min_val=float('inf')

for i in range(n-1):

  y=abs(sum(w[:i+1]) - sum(w[i+1:]))

  min_val = min(min_val, y)

print(min_val)
n, *w = list(map(int, open(0).read().split()))
min_val = None
for i in range(n - 1):
    y = abs(sum(w[: i + 1]) - sum(w[i + 1 :]))
    if min_val is None or y < min_val:
        min_val = y
print(min_val)

n, *w = list(map(int, open(0).read().split()))
min_val = float("inf")
for i in range(n - 1):
    y = abs(sum(w[: i + 1]) - sum(w[i + 1 :]))
    min_val = min(min_val, y)
print(min_val)

-min_val = None +min_val = float("inf") -    if min_val is None or y < min_val: -        min_val = y +    min_val = min(min_val, y)