from collections import deque



n = int(eval(input()))

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



d = deque(w)



s1 = d.popleft()

s2 = d.pop()



for _ in range(n-2):

	if s1 < s2:

		s1 += d.popleft()

	else:

		s2 += d.pop()



print((abs(s1 - s2)))

n = int(eval(input()))

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



ans = []

for i in range(1,n):

    ans.append(abs(sum(w[:i])-sum(w[i:])))



print((min(ans)))

from collections import deque

n = int(eval(input()))
w = list(map(int, input().split()))
d = deque(w)
s1 = d.popleft()
s2 = d.pop()
for _ in range(n - 2):
    if s1 < s2:
        s1 += d.popleft()
    else:
        s2 += d.pop()
print((abs(s1 - s2)))

n = int(eval(input()))
w = list(map(int, input().split()))
ans = []
for i in range(1, n):
    ans.append(abs(sum(w[:i]) - sum(w[i:])))
print((min(ans)))

-from collections import deque - -d = deque(w) -s1 = d.popleft() -s2 = d.pop() -for _ in range(n - 2): -    if s1 < s2: -        s1 += d.popleft() -    else: -        s2 += d.pop() -print((abs(s1 - s2))) +ans = [] +for i in range(1, n): +    ans.append(abs(sum(w[:i]) - sum(w[i:]))) +print((min(ans)))