Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.  Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut:    * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).   * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.  Find the minimum amount of money needed before cutting the bar into two parts with the same length.
n=int(input())
a=[int(i) for i in input().split()]
asum2=sum(a)//2
j,k=0,0
for i in range(n):
  j+=a[i]
  if j>=asum2:
    break
for i in range(n):
  k+=a[n-i-1]
  if k>=asum2:
    break
if j-asum2>k-asum2:
  if sum(a)%2==0:
    print(2*j-2*asum2)
  else:
    print(2*j-2*asum2+1)
else:
  if sum(a)%2==0:
    print(2*k-2*asum2)
  else:
    print(2*k-2*asum2+1)
  
 
n=int(input())
a=[int(i) for i in input().split()]
asum2=sum(a)/2
j,k=0,0
for i in range(n):
  j+=a[i]
  if j>=asum2:
    break
for i in range(n):
  k+=a[n-i-1]
  if k>=asum2:
    break
if j-asum2<k-asum2:
  print(int(2*j-2*asum2))
else:
  print(int(2*k-2*asum2))
 
  
 
