CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = list(map(int, input().split())) # 横入力

x = [0]
aaa = 0
aa = sum(a)
y = [aa]
for i in range(n):
    aaa += a[i]
    x.append(aaa)
    aa -= a[i]
    y.append(aa)

ans = 202020202020
for i in range(n+1):
    ans = min(ans, abs(x[i] - y[i]))

print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split())) # 横入力

x = [0]
aaa = 0
aa = sum(a)
# y = [aa]
for i in range(n):
    aaa += a[i]
    x.append(aaa)
    # aa -= a[i]
    # y.append(aa)

ans = 202020202020
for i in range(n+1):
    ans = min(ans, abs(aa - x[i]*2))

print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
suma=sum(a)
p=suma
for i in range(n):
    f=sum(a[:i])
    p=min(p,abs(suma-2*f))
print(p)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
suma=sum(a)
f=0
p=suma-2*f
for i in a:
    f+=i
    p=min(p,abs(suma-2*f))
print(p)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

Asum = sum(A)

sumdiflist = []

for i in range(N-1):
  B = A[:i+1]
  Bsum = sum(B) #前半の和
  temp = Asum - Bsum #後半の和
  sumdif = Bsum - temp
  if(sumdif<0):
    sumdif = -sumdif
  sumdiflist.append(sumdif)

print((min(sumdiflist)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

Asum = sum(A)
sumdiflist = []

temp = 0
for i in range(N-1):
  temp += A[i]
  sumdif = 2*temp - Asum
  if(sumdif<0):
    sumdif = -sumdif
  sumdiflist.append(sumdif)

print((min(sumdiflist)))
# Original solution
#!/usr/bin/env python3
n, *a = list(map(int, open(0).read().split()))
s = sum(a)
r = [sum(a[:i + 1]) for i in range(n)]
print((min(abs(2 * i - s) for i in r)))


# Optimized solution
#!/usr/bin/env python3
n, *a = list(map(int, open(0).read().split()))
s = sum(a)
r = [a[0]]
for i in range(1, n):
    r.append(r[i - 1] + a[i])
print((min(abs(2 * i - s) for i in r)))
# Original solution
#!/usr/bin/env python3
n, *a = list(map(int, open(0).read().split()))
s = sum(a)
r = [a[0]]
for i in range(1, n):
    r.append(r[i - 1] + a[i])
print((min(abs(2 * i - s) for i in r)))


# Optimized solution
#!/usr/bin/env python3
n, *a = list(map(int, open(0).read().split()))
r = [a[0]]
for i in range(1, n):
    r.append(r[i - 1] + a[i])
print((min(abs(2 * i - r[-1]) for i in r)))
# Original solution
N = int(eval(input()))

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

d = []
for i in range(1, len(A_list)):
		left = sum(A_list[:i])
		right = sum(A_list[i:])
		temp = abs(left - right)
		d.append(temp)

print((min(d)))


# Optimized solution
N = int(eval(input()))

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

left = 0
A_sum = sum(A_list)
ans = A_sum
for a in A_list:
		left += a
		right = A_sum - left
		ans = min(ans, abs(left-right))

print(ans)
# Original solution
n = int(eval(input()))
li = list(map(int,input().split()))
s = sum(li)
sum_li = []
for i,l in enumerate(li):
    if i == 0:
        sum_li.append(l)
        continue
    sum_li.append(sum_li[-1]+l)
all_li = []
for ii,ss in enumerate(sum_li):
    if ii == len(sum_li)-1:
        break
    all_li.append(abs(s-2*ss))
#print(all_li)
print((min(all_li)))

# Optimized solution
n = int(eval(input()))
li = list(map(int,input().split()))
s = sum(li)
sum_li = []
left = 0
right = s
for i,l in enumerate(li):
    if i == len(li)-1:
        break
    left += l
    right -= l
    sum_li.append(abs(left-right))
print((min(sum_li)))
# Original solution
def main():
    N=int(eval(input()))
    A=[int(_) for _ in input().split()]
    ans = sum(A)-A[0]
    for i in range(N):
        ans = min(ans, abs(sum(A[:i]) - sum(A[i:])))
    print(ans)

main()

# Optimized solution
def main():
    N=int(eval(input()))
    A=[int(_) for _ in input().split()]
    left=0
    right=sum(A)
    ans=right
    for i in range(N):
        left+=A[i]
        right-=A[i]
        ans = min(ans, abs(left-right))
    print(ans)

main()
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
l = A.pop(0)
r = A.pop(-1)

for i in range(n-2):
  if r<l:
    r+=A.pop(-1)
  else:
    l+=A.pop(0)
  
print((abs(r-l)))

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
l = A.pop(0)
idxl = 0
r = A.pop(-1)
idxr = -1

for i in range(n-2):
  if r<l:
    r+=A[idxr]
    idxr -= 1
  else:
    l+=A[idxl]
    idxl += 1
  
print((abs(r-l)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 10 ** 10
for i in range(1, len(a)):
    ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
L = sum(a)
l = 0
i = 0
while l < L / 2:
    l += a[i]
    i += 1
print((min(abs(sum(a[:i - 1]) - sum(a[i - 1:])), abs(sum(a[:i]) - sum(a[i:])))))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

for i in range(n):
    tmp = abs(sum(a[:i])-sum(a[i:]))
    ans = tmp if i==0 else min(ans, tmp)

print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
t = sum(a)
b = 0

for i in range(n):
    b += a[i]
    tmp = abs(2*b-t)
    ans = tmp if i==0 else min(ans, tmp)

print(ans)
# Original solution
N = int(eval(input()))
A = [int(s) for s in input().split()]

minimum = sum(A)
for i, l in enumerate(A):
  a = sum(A[:i])
  b = sum(A[i:])
  minimum = min(minimum, abs(a-b))
print(minimum)

# Optimized solution
N = int(eval(input()))
A = [int(s) for s in input().split()]

minimum = sum(A)
a = 0
b = minimum
for i, l in enumerate(A):
  a += l
  b -= l
  minimum = min(minimum, abs(a-b))
print(minimum)
# Original solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(eval(input()))
a = list(map(int, input().split()))
x = 0
y = 0
for i in range(0, n):
    if x <= y:
        x += a.pop(0)
    else:
        y += a.pop(-1)
print((abs(x - y)))

# Optimized solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(eval(input()))
a = list(map(int, input().split()))
x = 0
y = 0
be = 0
af = -1
for i in range(0, n):
    if x <= y:
        x += a[be]
        be += 1
    else:
        y += a[af]
        af -= 1
print((abs(x - y)))
# Original solution
import sys

n = int(eval(input()))

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

cnt = 0
ave = sum(a)/2

for i in range(n):
    cnt += a[i]
    if cnt == ave:
        print((0))
        sys.exit()
    
    elif cnt > ave:
        x = ave -cnt +a[i]
        if x >= cnt -ave:
            x = cnt -ave
        break

print((int(x*2)))

# Optimized solution
n = int(eval(input()))

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

cnt = 0
ave = sum(a)/2

for i in range(n):
    cnt += a[i]
    if cnt >= ave:
        ans = min(cnt*2-ave*2, ave*2-(cnt-a[i])*2)
        break

print((int(ans)))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))

sa=float("inf")

for i in range(n-1):
  wa1=sum(a[0:1+i])
  wa2=sum(a[1+i:])
  temp=abs(wa1-wa2)
  sa=min(sa,temp)
print(sa)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))

sa=float("inf")


wa1=0
wa2=sum(a)

for i in range(n-1):
  wa1+=a[i]
  wa2-=a[i]
  temp=abs(wa1-wa2)
  sa=min(sa,temp)
print(sa)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
su=sum(a)
c=[]#[abs(sum(a[:i+1])-su/2)*2 for i in range(n)]

for i in range(n):
  c+=[abs(sum(a[:i+1])-su/2)*2]
  if sum(a[:i+1])-su/2 >0 or sum(a[:i+1])-su/2==0:
    break
print((int(min(c))))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
import itertools
b = list(itertools.accumulate(a))
for i in range(n):
  b[i] = abs(2*b[i]-b[-1])
print((min(b)))
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    s = sum(A)
    a = []
    b = []
    for i in range(len(A)):
        if s % 2 != 0:
            if sum(a) >= (s // 2) - 1 or i == N-1:
                b.append(A[i])
            else:
                a.append(A[i])
        else:
            if sum(a) >= (s // 2) or i == N-1:
                b.append(A[i])
            else:
                a.append(A[i])
    ans1 = abs(sum(a)-sum(b))
    ans2 = abs(sum(a[:-1])-sum(b+[a[-1]]))
    print((min(ans1, ans2)))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    s = sum(A)
    a = 0
    b = 0
    tmp = []
    for i in range(len(A)):
        if s % 2 != 0:
            if a >= (s // 2) - 1 or i == N-1:
                b += A[i]
            else:
                a += A[i]
                tmp.append(A[i])
        else:
            if a >= (s // 2) or i == N-1:
                b += A[i]
            else:
                a += A[i]
                tmp.append(A[i])
    ans1 = abs(a-b)
    ans2 = abs((a-tmp[-1]) - (b+tmp[-1]))
    print((min(ans1, ans2)))


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
cost_1 = 0
cost_2 = 0
cost_3 = 0
cost_4 = 0
S = sum(A)
S_1 = sum(A)
S_2 = sum(A)
S_3 = sum(A)
S_4 = sum(A)
half = S / 2
l = 0
i = 0
while l < half:
    l += A[i]
    i += 1
l_big = l
l_small = l - A[i-1]
if l_big == S - l:
    print((0))
elif l_big - half < half - l_small:
    l_1 = l_big
    l_2 = l_big
    while l_1 > S_1 - l_big:
        l_1 -= 1
        cost_1 += 1
    while l_2 > S_2 - l_big:
        l_2 -= 1
        cost_2 += 1
    print((min(cost_1, cost_2)))
else:
    l_3 = l_small
    l_4 = l_small
    while l_3 < S_3 - l_small:
        l_3 += 1
        cost_3 += 1
    while l_4 < S_4 - l_small:
        l_4 += 1
        cost_4 += 1
    print((min(cost_3, cost_4)))

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
B = A[::-1]
S = [0] * n
S[0] = A[0]
T = [0] * n
T[0] = B[0]
ans = float('inf')
for i in range(1, n):
    S[i] = S[i - 1] + A[i]
    T[i] = T[i - 1] + B[i]
T = T[::-1]
ans = 2020202020 + 1
for i in range(n):
    diff = abs(S[i] - T[i] - A[i])
    ans = min(ans, diff)
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
tmp_x = -1
tmp_x_diff = -1
for i in range(N - 1):
    sum1 = sum(A[:i + 1])
    sum2 = sum(A[i + 1:])
    diff = abs(sum1 - sum2)
    if tmp_x_diff == -1 or diff < tmp_x_diff:
        tmp_x = i
        tmp_x_diff = diff
print(tmp_x_diff)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

cumsum = [0]
for i in range(N):
    cumsum.append(cumsum[-1] + A[i])

tmp_x = -1
tmp_x_diff = -1
for i in range(N - 1):
    sum1 = cumsum[i + 1]
    sum2 = cumsum[-1] - cumsum[i + 1]
    diff = abs(sum2 - sum1)
    if tmp_x_diff == -1 or diff < tmp_x_diff:
        tmp_x = i
        tmp_x_diff = diff
print(tmp_x_diff)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
ar =[]


for i in range(1, N):
  ar.append(abs(sum(A[:i]) - sum(A[i:])))
print((min(ar)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
s = sum(A)

av = s / 2
x = 0
y = 0

for i in range(N):
  x += A[i]
  
  if x < av < x +A[i+1]:
    
    y = s - x - A[i+1]
    
    if x > y:
      print((A[i+1]-x+y))
      
    else:
      print((A[i+1]-y+x))
  elif x == av:
    print((0))
# Original solution
def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    s = [0] * (N + 1)
    for i in range(0, N):
        s[i+1] = s[i] + A[i]
    ans = (1 << 63) - 1
    for j in range(1, N):
        left = s[j] - s[0]
        right = s[N] - s[j]
        ans = min(ans, abs(right - left))
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    acc = [a for a in accumulate([0] + A)]
    ans = acc[-1]
    for i in range(1, N+1):
        a = acc[i]
        b = acc[N] - acc[i]
        v = abs(a-b)
        ans = min(ans, v)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
sum1 = []
sum2 = []
s = sum(a)
ls = []
for i in range(1,n):
    sum1.append(sum(a[:i]))
    sum2.append(s - sum(a[:i]))

for i in range(n-1):
    ls.append(abs(sum1[i] - sum2[i]))

print((min(ls)))


# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
sum1 = [a[0]]
sum2 = [sum(a)-a[0]]
s = sum(a)
ls = []
for i in range(1,n):
    sum1.append(sum1[i-1]+a[i])
    sum2.append(s - sum1[i])

for i in range(n-1):
    ls.append(abs(sum1[i] - sum2[i]))

print((min(ls)))
# Original solution
import sys

N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))
S = [0] * (N + 1)
s = sum(A)

for i in range(N):
    S[i + 1] += S[i] + A[i]

mini = 10 ** 18
for i in range(1, N + 1):
    mini = min(mini, abs(S[N] - 2 * S[i]))

print(mini)


# Optimized solution
import sys, itertools

N = int(eval(input()))
A = list(map(int, sys.stdin.readline().rsplit()))

S = list(itertools.accumulate(A))

mini = 10 ** 18
for i in range(N):
    mini = min(mini, abs(S[N - 1] - 2 * S[i]))

print(mini)
# Original solution
'''
参考
https://qiita.com/c-yan/items/f7c99c8f8ec418a58c42

棒の全長をL、切断箇所をCとすると、かかるコストは|2C-L|となる
（左端から切断箇所までの長さを2倍し、元の棒の全長を引いたものの絶対値）
∵
・CがL/2よりも左にある場合（=棒の左端からCまでの長さのほうが短い）
⇒Cよりも左側に2C-L足すか、右側を2C-L減らす
・CがL/2よりも右にある場合（=棒の左端からCまでの長さのほうが長い）
⇒Cよりも左側を2C-L減らすか、右側に2C-L足す

与えられたリストAのうち、どの地点をCとするかは
リストAの先頭の要素からN-1個の要素をそれぞれ調べ、
先頭要素から現在の要素までの合計（累積和）を格納するリストを別途作成、
そのリストに対して|2C-L|が最小となるケースを調べる
'''
N = int(eval(input()))
A = list(map(int, input().split()))
L = sum(A)
tmp = []

for i in range(N):
    tmp.append(sum(A[:i+1]))

cost = min(abs(c*2-L) for c in tmp)
print(cost)


# Optimized solution
'''
参考
https://qiita.com/c-yan/items/f7c99c8f8ec418a58c42

棒の全長をL、切断箇所をCとすると、かかるコストは|2C-L|となる
（左端から切断箇所までの長さを2倍し、元の棒の全長を引いたものの絶対値）
∵
・CがL/2よりも左にある場合（=棒の左端からCまでの長さのほうが短い）
⇒Cよりも左側に2C-L足すか、右側を2C-L減らす
・CがL/2よりも右にある場合（=棒の左端からCまでの長さのほうが長い）
⇒Cよりも左側を2C-L減らすか、右側に2C-L足す

与えられたリストAのうち、どの地点をCとするかは
リストAの先頭の要素からN-1個の要素をそれぞれ調べ、
先頭要素から現在の要素までの合計（累積和）を格納するリストを別途作成、
そのリストに対して|2C-L|が最小となるケースを調べる
'''
N = int(eval(input()))
A = list(map(int, input().split()))
L = sum(A)
#tmp = []
tmp = A[:-1]

for i in range(1, N-1):
#    tmp.append(sum(A[:i+1]))       # 実行時間超過してしまうためコメントアウト
    tmp[i] += tmp[i-1]

cost = min(abs(c*2-L) for c in tmp)
print(cost)
# Original solution
def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    diff = 10 ** 10
    for i in range(N):
        partA = sum(A[:i])
        partB = sum(A[i:])
        diff = min(diff, abs(partA-partB))
    
    print(diff)
    return
resolve()

# Optimized solution
def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    diff = 10 ** 10

    partA = 0
    partB = sum(A)

    for i in range(N):
        diff = min(diff, abs(partA-partB))
        partA += A[i]
        partB -= A[i]
    print(diff)
    return
resolve()
# Original solution
n=int(eval(input()))
L=list(map(int,input().split()))
sumL=sum(L)
ans=2020202020
tmp1=0
tmp2=0
for i in range(n):
    for j in range(i):
        tmp1+=L[j]
    tmp2=sumL-tmp1
    ans=min(ans,abs(tmp1-tmp2))
    tmp1=0
    tmp2=0
print(ans)

# Optimized solution
n=int(eval(input()))
L=list(map(int,input().split()))
sumL=[0 for _ in range(n)]
S=sum(L)
for i in range(n):
    if i==0:
        sumL[i]=L[i]
    else:
        sumL[i]=sumL[i-1]+L[i]
ans=2020202020
tmp1=0
tmp2=0
for i in range(n):
    tmp1=sumL[i]
    tmp2=S-sumL[i]
    ans=min(ans,abs(tmp1-tmp2))
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(abs(sum(a[:i])-sum(a[i:])))
print((min(h)))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

result = [[a[0], sum(a[1:])]]
for i in range(1, n):
    result.append([result[-1][0]+a[i], result[-1][1]-a[i]])
h = []
for i in range(len(result)):
    h.append(abs(result[i][0]-result[i][1]))
print((min(h)))
# Original solution
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))

    a = [0] * n
    b = [0] * n
    for i in range(n):
        if i == 0:
            a[i] = v[i]
            continue
        a[i] = a[i-1] + v[i]
    for i in reversed(list(range(n))):
        if i == n-1:
            b[i] = v[i]
            continue
        b[i] = b[i+1] + v[i]
    ans = INF
    for i in range(n-1):
        ans = min(ans, abs(a[i] - b[i+1]))
    print(ans)
if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def calc_sum(v, n):
    a = [0] * (n)
    for i in range(n):
        if i == 0:
            a[i] = v[i]
            continue
        a[i] = a[i-1] + v[i]
    return a

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))

    a = calc_sum(v, n)
    b = list(reversed(calc_sum(list(reversed(v)), n)))

    ans = INF
    for i in range(n-1):
        ans = min(ans, abs(a[i] - b[i+1]))
    print(ans)
if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
tmp = 0
for i in range(len(a)):
         tmp += a[i]
         if tmp >= (sum(a))//2:
                  break
print((min((abs((sum(a)-tmp)-tmp)),abs((sum(a)-(tmp-a[i]))-(tmp-a[i])))))


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
suma = sum(a)
tmp = 0
for i in range(len(a)):
         tmp += a[i]
         if tmp >= suma//2:
                  break
print((min((abs((suma-tmp)-tmp)),abs((suma-(tmp-a[i]))-(tmp-a[i])))))
# Original solution
n = int(eval(input()))

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

L = sum(a)

nagasa = 0

ans = 0

i=0
while(i < len(a)):
  nagasa += a[i]
  if nagasa == L/2:
    break
  elif nagasa > L/2:
    sa1 = L/2 - sum(a[0:i])
    sa2 = nagasa - L/2
  
    if sa1 < sa2:
      # 後ろを減らす
      a[i] -= 1
    else:
      # 前を減らす
      a[i-1] -= 1
    
    L = sum(a)
    ans += 1
    i = 0
    nagasa = 0
  else:
    i+=1

print(ans)



    



# Optimized solution
n = int(eval(input()))

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

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa*2 >= L:
    ans = min(abs(L - (nagasa *2)), abs(L - ((nagasa-a[i])*2)))

    break
    

print(ans)
# Original solution
N = int(eval(input()))
length = [int(i) for i in input().split()]
pos = []

for a in range(len(length)+1):
    x = sum(length[:a])
    y = sum(length[a:])
    pos.append(max(x,y) - min(x,y))
    # print("pos " + str(a)+":",sum(length[:a]), sum(length[a:]))
# print(pos)

print((min(pos)))

# Optimized solution
N = int(eval(input()))
length = [int(i) for i in input().split()]
pos = []
s1 = sum(length)
s2 = 0

for a in range(len(length)):
    pos.append(max(s1,s2) - min(s1,s2))
    s1 -= length[a]
    s2 += length[a]
    # print("pos " + str(a)+":",sum(length[:a]), sum(length[a:]))
# print(pos)

print((min(pos)))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))


diff = 2020202020 * 200000 + 1
tot = sum(A)

for i in range(N):
    temp1 = A[:i+1]
    # temp2 = A[i+1:]
    temp3 = abs(tot - 2 * sum(temp1))
    if temp3 <= diff:
        # mid = i
        diff = temp3
    else:
        break

print(diff)


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))


diff = 2020202020 * 200000 + 1
tot = sum(A)

temp1 = 0

for i in range(N):
    temp1 += A[i]
    # temp2 = A[i+1:]
    temp3 = abs(tot - 2 * temp1)
    if temp3 <= diff:
        # mid = i
        diff = temp3
    else:
        break

print(diff)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt=0
i=0
while cnt<sum(a)//2:
    temp=cnt
    cnt+=a[i]
    i+=1
print((min(abs(sum(a)-temp*2),abs(sum(a)-cnt*2))))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt=0
i=0
s=sum(a)
while cnt<s//2:
    temp=cnt
    cnt+=a[i]
    i+=1
    
print((min(abs(sum(a)-temp*2),abs(sum(a)-cnt*2))))
# Original solution
num=int(eval(input()))
mm=[int(s) for s in input().split()]
total=sum(mm)


count=0
for j,i in enumerate(mm):
  count+=i
  if count>=total//2:
    flag=j
    break
p=0
q=sum([mm[i+1] for i in range(flag,len(mm)-1)])
while True:
  if count>q:
    q+=1
    p+=1
  else:
    break


mm.reverse()

count=0
for j,i in enumerate(mm):
  count+=i
  if count>=total//2:
    flag=j
    break
p2=0
q=sum([mm[i+1] for i in range(flag,len(mm)-1)])
while True:
  if count>q:
    q+=1
    p2+=1
  else:
    break

if p>=p2:
  print(p2)
else:
  print(p)

# Optimized solution
num=int(eval(input()))
mm=[int(s) for s in input().split()]
total=sum(mm)


count=0
for j,i in enumerate(mm):
  count+=i
  if count>=total//2:
    flag=j
    break

q=sum(mm[flag+1:])

p=count-q


mm.reverse()

count=0
for j,i in enumerate(mm):
  count+=i
  if count>=total//2:
    flag=j
    break

q=sum(mm[flag+1:])
p2=count-q

if p>=p2:
  print(p2)
else:
  print(p)
# Original solution
n = int(eval(input()))
a_inputs = list(map(int,input().split()))
len_bar = sum(a_inputs)

gap = float('inf')
for i in range(n-1):
    g = abs(len_bar-2*sum(a_inputs[:i+1]))
    if g<gap:
        gap=g
print(gap)


# Optimized solution
n = int(eval(input()))
a_inputs = list(map(int,input().split()))
len_bar = sum(a_inputs)

cum_bar = [0]*n
cum_bar[0]=a_inputs[0]
for i in range(1,n):
    cum_bar[i]=cum_bar[i-1]+a_inputs[i]

gap = float('inf')
for i in range(n-1):
    g = abs(len_bar-2*cum_bar[i])
    if g<gap:
        gap=g
print(gap)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
ans=float("inf")
s=sum(A)
k=0
for i in range(N-1):
    k+=A[i]
    ans=min(ans,abs(s-2*k))
print(ans)

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
s=ans=sum(A)
k=0
for i in range(N-1):
    k+=A[i]
    ans=min(ans,abs(s-2*k))
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

for i in range(1,n):
    a[i] += a[i-1]

c = a[-1]
for i in range(n):
    c = min(c, abs(a[-1]-a[i]*2))
print(c) 

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
c = a[-1]
for i in range(n):
    p = abs(a[-1]-a[i]*2)
    if c > p:
        c = p   
print(c)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

Asum = sum(A)
ans = float('inf')
for i in range(len(A)-1):
    s = sum(A[:i+1])
    t = Asum - s
    ans = min(ans, abs(s-t))

print(ans)

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))

cum = [0]
for a in A:
    cum.append(cum[-1]+a)

ans = float('inf')
for i in range(n-1):
    s = cum[i+1]
    t = cum[-1] - s
    ans = min(ans, abs(s-t))

print(ans)
# Original solution
n = int(eval(input()))

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

total = sum(stick)
mid = total // 2

cum = 0
midi = 0
for i, block in enumerate(stick):
    cum += block
    if cum >= mid:
        midi = i
        break

l1 = sum(stick[:midi])
r1 = sum(stick[midi:])
diff1 = abs(l1 - r1)
 
l2 = l1 + stick[midi]
r2 = r1 - stick[midi]
diff2 = abs(l2 - r2)
 
print((min(diff1, diff2)))

# Optimized solution
import sys
input = sys.stdin.readline

def main():
    n = int(eval(input()))

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

    total = sum(stick)
    mid = total // 2

    cum = 0
    midi = 0
    for i, block in enumerate(stick):
        cum += block
        if cum >= mid:
            midi = i
            break

    l1 = sum(stick[:midi])
    r1 = sum(stick[midi:])
    diff1 = abs(l1 - r1)
    
    l2 = l1 + stick[midi]
    r2 = r1 - stick[midi]
    diff2 = abs(l2 - r2)
    
    print((min(diff1, diff2)))

main()