from itertools import accumulate
n=int(input())
w=list(map(int,input().split()))
w=list(accumulate(w))
for i in range(n):
  if w[i]*2==w[-1]:
    print(0)
    break
  elif w[i]*2>w[-1]:
    print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)))
    break from itertools import accumulate 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 w=list(accumulate(w)) w list(accumulate(w)) list accumulate(w) accumulate w for i in range(n):
  if w[i]*2==w[-1]:
    print(0)
    break
  elif w[i]*2>w[-1]:
    print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)))
    break i range(n) range n if w[i]*2==w[-1]:
    print(0)
    break
  elif w[i]*2>w[-1]:
    print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)))
    break w[i]*2==w[-1] w[i]*2 w[i] w i 2 w[-1] w -1 print(0) print 0 break elif w[i]*2>w[-1]:
    print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)))
    break w[i]*2>w[-1] w[i]*2 w[i] w i 2 w[-1] w -1 print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2))) print min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)) min w[i]*2-w[-1] w[i]*2 w[i] w i 2 w[-1] w -1 w[-1]-w[i-1]*2 w[-1] w -1 w[i-1]*2 w[i-1] w i-1 i 1 2 break w=list(accumulate(w)) list(accumulate(w)) w n=int(input()) int(input()) n w=list(map(int,input().split())) list(map(int,input().split())) w
from itertools import accumulate
n=int(input())
w=list(map(int,input().split()))
w=list(accumulate(w))
for i in range(n):
  if w[i]*2==w[-1]:
    print(0)
    break
  elif w[i]*2>w[-1]:
    print(min((w[i]*2-w[-1]),(w[-1]-w[i-1]*2)))
    break