a=int(input())
b=list(map(int,input().split()))
c=sum(b)
d=0
e=0
f=0
for i in range(a):
  d=d+b[i]
  if d>=c/2:
    e=i
    break
for i in range(e):
  f=f+b[i]
if abs(d-(c-d))<abs(f-(c-f)):
  print(abs(d-(c-d)))
else:
  print(abs(f-(c-f))) a=int(input()) a int(input()) int input() input b=list(map(int,input().split())) b list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c=sum(b) c sum(b) sum b d=0 d 0 e=0 e 0 f=0 f 0 for i in range(a):
  d=d+b[i]
  if d>=c/2:
    e=i
    break i range(a) range a d=d+b[i] d d+b[i] d b[i] b i if d>=c/2:
    e=i
    break d>=c/2 d c/2 c 2 e=i e i break for i in range(e):
  f=f+b[i] i range(e) range e f=f+b[i] f f+b[i] f b[i] b i if abs(d-(c-d))<abs(f-(c-f)):
  print(abs(d-(c-d)))
else:
  print(abs(f-(c-f))) abs(d-(c-d))<abs(f-(c-f)) abs(d-(c-d)) abs d-(c-d) d c-d c d abs(f-(c-f)) abs f-(c-f) f c-f c f print(abs(d-(c-d))) print abs(d-(c-d)) abs d-(c-d) d c-d c d print(abs(f-(c-f))) print abs(f-(c-f)) abs f-(c-f) f c-f c f c=sum(b) sum(b) c a=int(input()) int(input()) a d=d+b[i] d+b[i] d e=i i e b=list(map(int,input().split())) list(map(int,input().split())) b d=0 0 d f=f+b[i] f+b[i] f e=0 0 e f=0 0 f
a=int(input())
b=list(map(int,input().split()))
c=sum(b)
d=0
e=0
f=0
for i in range(a):
  d=d+b[i]
  if d>=c/2:
    e=i
    break
for i in range(e):
  f=f+b[i]
if abs(d-(c-d))<abs(f-(c-f)):
  print(abs(d-(c-d)))
else:
  print(abs(f-(c-f)))