import sys
sys.setrecursionlimit(10**6)

n = int(input())
w = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

total = sum(w)
s1 = 0
s2 = total
ans = abs(s1-s2)

for i in w:
    s1 += i
    s2 -= i
    if abs(s1-s2) < ans:
        ans = abs(s1-s2)
        
print(ans) import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 n = int(input()) n int(input()) int input() input w = list(map(int, input().split())) w list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split total = sum(w) total sum(w) sum w s1 = 0 s1 0 s2 = total s2 total ans = abs(s1-s2) ans abs(s1-s2) abs s1-s2 s1 s2 for i in w:
    s1 += i
    s2 -= i
    if abs(s1-s2) < ans:
        ans = abs(s1-s2)
         i w s1 += i s1 i s2 -= i s2 i if abs(s1-s2) < ans:
        ans = abs(s1-s2)
         abs(s1-s2) < ans abs(s1-s2) abs s1-s2 s1 s2 ans ans = abs(s1-s2) ans abs(s1-s2) abs s1-s2 s1 s2 print(ans) print ans ans = abs(s1-s2) abs(s1-s2) ans total = sum(w) sum(w) total s1 = 0 0 s1 s1 += i i s1 n = int(input()) int(input()) n w = list(map(int, input().split())) list(map(int, input().split())) w s2 -= i i s2 ans = abs(s1-s2) abs(s1-s2) ans s2 = total total s2
import sys
sys.setrecursionlimit(10**6)

n = int(input())
w = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

total = sum(w)
s1 = 0
s2 = total
ans = abs(s1-s2)

for i in w:
    s1 += i
    s2 -= i
    if abs(s1-s2) < ans:
        ans = abs(s1-s2)
        
print(ans)