CodeEff/ECCO huggingface dataset:
# Original 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()

# 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 = cum
    r1 = total - l1
    diff1 = abs(l1 - r1)
    
    l2 = l1 - stick[midi]
    r2 = r1 + stick[midi]
    diff2 = abs(l2 - r2)
    
    print((min(diff1, diff2)))

main()
# Original solution
N = int(eval(input()))

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

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

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

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

cand = []
left = 0
right = sum(A)
for i in range(N-1):
    left += A[i]
    right -= A[i]
    diff = abs(left - right)
    cand.append(diff)
print((min(cand)))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=float('inf')
for i in range(n):
  d=abs(sum(a[0:i+1])-sum(a[i+1:n]))
  ans=min(ans,d)
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=float('inf')
s=sum(a)
res=0
for i in range(n):
  res+=a[i]
  s-=a[i]
  ans=min(ans,abs(s-res))
print(ans)
# Original solution
n=int(eval(input()))

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

if n==2:
  print((abs(r[0]-r[1])))
  exit()

border=sum(r)//2+1
result="INF"
for i in range(1,n):
  #print(r[:i],r[i:])
  if result=="INF":
    result=abs(sum(r[:i])-sum(r[i:]))
  else:
    result=min(result,abs(sum(r[:i])-sum(r[i:])))
  
  if sum(r[:i])>=border:
    print(result)
    exit()
print(result)
  





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

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

if n==2:
  print((abs(r[0]-r[1])))
  exit()
 

#print(r)

temp=sum(r)

goukei=0
for item in r:
  if goukei+item>=temp/2.0:
    
    if abs(temp-goukei-goukei)<=abs((temp-(goukei+item))-(goukei+item)):
      print((abs(temp-goukei-goukei)))
    else:
      print((abs((temp-(goukei+item))-(goukei+item))))
    exit()
  goukei=goukei+item
  
goukei=goukei-item
  
print((abs(temp-(goukei-item))))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

s = sum(A)
B = [0]
for i in range(N):
    B.append(B[i] + A[i])

ans = float('inf')
for i in range(1, N):
    ans = min(ans, abs(s-(2*B[i])))

print(ans)


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

s = sum(A)
B = [0]
for i in range(N):
    B.append(B[i] + A[i])

ans = float('inf')
for i in range(1, N):
    _ans = ans
    ans = min(ans, abs(B[i] - (s - B[i])))
    if ans > _ans:
        break

print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 100000000000000
for i in range(n):
  if sum(a[:i]) == sum(a[i:]):
    ans = 0
    break
  elif ans > abs(sum(a[:i]) - sum(a[i:])):
    ans = abs(sum(a[:i]) - sum(a[i:]))
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = sum(a)
al = ans
mod = 0
for i in range(n):
  if mod + a[i] == al - a[i]:
    ans = 0
    break
  elif ans > abs(mod - al + 2*a[i]):
    ans = abs(mod - al + 2*a[i])
    mod += a[i]
    al -= a[i]
  else:
    mod += a[i]
    al -= a[i]
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = float('inf') 
sum_A = sum(A)
CumSum = 0


for i in range(N-1):
  CumSum = CumSum + A[i]
  ans = min(ans,(abs((sum_A - CumSum)-(CumSum))))

print(ans)


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

ans = (2020202020)**100
sum_A = sum(A)
hoge = 0


for i in range(N-1):
  hoge = hoge + A[i]
  ans = min(ans,(abs(sum_A - (hoge*2))))

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

m = 10**10
for i in range(n):
    x = sum(a[:i])
    y = sum(a[i:])
    m = min(abs(x-y),m)
print(m)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
m = 10**10
x = sum(a)
y = 0
for i in range(n):
    x -= a[i]
    y += a[i]
    m = min(abs(x-y),m)
print(m)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
c=0
d=float("INF")
for i in range(n):
    c+=a[i]
    d=min(d,abs(sum(a)-2*c))
print(d)


# Optimized solution
from itertools import accumulate as ac
n=int(eval(input()))
a=list(ac(list(map(int,input().split()))))
d=float("INF")
for i in range(n):
    d=min(d,abs(a[-1]-2*a[i]))
print(d)
# Original solution
n=int(eval(input()))
A=list(map(int,input().split()))


sa=float('inf')
for i in range(n):
  sa=min(sa,abs(sum(A[:i])-sum(A[i:])))
print(sa)


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

l=0
r=sum(A)
ans=float('inf')
for i in range(n):
  l+=A[i]
  r-=A[i]
  ans=min(ans,abs(l-r))
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
tot = sum(A)
B = [0 for _ in range(N-1)]
cnt = A[0]
for i in range(1,N):
    B[i-1] = abs(tot-2*cnt)
    cnt += A[i]
print((min(B)))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
tot = sum(A)
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
cmin = abs(tot-2*B[1])
for i in range(2,N):
    cmin = min(cmin,abs(tot-2*B[i]))
print(cmin)
# Original solution
N = int(eval(input()))

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

A_sum = 0

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

min = A_sum

for i in range(N):
    AA_sum = 0
    for j in range(i):
        AA_sum += A[j]
    AA_sa = 2*AA_sum - A_sum
    if AA_sa < 0:
        AA_sa = -1 * AA_sa
    if AA_sa < min:
        min = AA_sa
print(min)

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

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

Asum = 0
A_sum = []

for i in range(N):
    Asum += A[i]
    A_sum.append(Asum)

for i in range(N):
    A_sum[i] = 2*A_sum[i] - Asum
    if A_sum[i] < 0:
        A_sum[i] = -1 * A_sum[i]

print((min(A_sum)))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
mindif = 1e15
minidx=0
for i in range(1,N):
    dif = abs(sum(a[:i])-sum(a[i:]))
    if dif<mindif:
        mindif = dif
        minidx = i
    else:
        break
print(mindif)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
r = sum(a)
ra = 0
result = 1e30
for i in range(0,N):
    ra += a[i]
    r -= a[i]
    result = min(result, abs(ra-r))
print((int(result)))
# Original solution
def resolve():
    n = int(eval(input()))
    A = list(map(int, input().split()))

    mid = 0
    diff = float("inf")
    for i in range(1, n):
        if abs(sum(A[:i]) - sum(A[i:])) <= diff:
            diff = abs(sum(A[:i]) - sum(A[i:]))
            mid = i
    
    front = A[:mid] 
    back =  A[mid:]
    print((abs(sum(front)-sum(back))))
resolve()

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

    mid = 0
    diff = float("inf")
    total = sum(A)
    p = 0
    # print(total)
    for i in range(n):
        # print("i:",i, "total:", total, "p:", p, "diff:", diff)
        if abs(total-p) < diff:
            diff = abs(total - p)
            mid = i
        p += A[i]
        total -= A[i]
    front = A[:mid] 
    back =  A[mid:]
    print((abs(sum(front)-sum(back))))
resolve()
# Original solution
# For taking integer inputs.
import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(eval(input())))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = eval(input())
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(list(map(int, input().split())))


n = inp()
a = inlist()
D = 10000000000000000
mid = 0
for i in range(1, n):

    s1 = sum(a[:i])
    s2 = sum(a[i:])

    d = abs(s1 - s2)

    if d < D:
        mid = i
        D = d
s1 = sum(a[:mid])
s2 = sum(a[mid:])
res = abs(s1-s2)
print(res)


# Optimized solution
# For taking integer inputs.
import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(eval(input())))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = eval(input())
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(list(map(int, input().split())))


n = inp()
a = inlist()
pref = [0] * (n)
suf = [0] * n
pref[0] = a[0]
suf[n-1] = a[n-1]
j = n - 2
for i in range(1, n):
    pref[i] = a[i] + pref[i-1]
    suf[j] = a[j] + suf[j+1]
    j -= 1

D = 10000000000000000
for i in range(0, n-1):

    s1 = pref[i]
    s2 = suf[i+1]
    d = abs(s1 - s2)
    if d < D:

        D = d

print(D)
# Original solution
N = int(eval(input()))
a=list(map(int,input().split()))
ans=2020202020
for i in range(1,N):
    mae=sum(a[:i])
    ato=sum(a)-mae
    ans=min(ans,abs(mae-ato))
print(ans)

# Optimized solution
N = int(eval(input()))
a=list(map(int,input().split()))
ans=2020202020
s=sum(a)
mae=a[0]
for i in range(1,N):
    mae+=a[i]
    ato=s-mae
    if mae-ato>0:
        ans=min(abs(sum(a[:i])-sum(a[i:])),abs(sum(a[:i+1])-sum(a[i+1:])))
        break
    else:
        ans=min(ans,abs(mae-ato))
print(ans)
# Original solution
n=int(eval(input()))
A=list(map(int,input().split()))
m=float('inf')
s=sum(A)
for i in range(len(A)):
    m=min(m,abs(2*sum(A[0:i])-s))
print(m)

# Optimized solution
n=int(eval(input()))
A=list(map(int,input().split()))
ans=float('INF')
sa=[0]
for i,a in enumerate(A):
    sa.append(sa[i]+a)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]

ans = float("inf")

for i in range(N):
	ans = min(ans, abs(sum(A[:i])-sum(A[i:])))

print(ans)

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

l = sum(A)
ans = float("inf")
t = 0

for i in range(N-1):
	t += A[i]
	ans = min(ans,abs(l-2*t))
	#print("t,ans",t,ans)

print(ans)
# Original solution
n,*a=list(map(int,open(0).read().split()))
s=sum(a)
for i in range(1,n):a[i]+=a[i-1]
print((min(abs(t*2-s)for t in a)))

# Optimized solution
n,*a=list(map(int,open(0).read().split()))
s=sum(a)
c=0
m=[]
for b in a:c+=b;m+=abs(c+c-s),
print((min(m)))
# Original solution
_,a=open(0)
*a,=list(map(int,a.split()))
s=sum(a)
c=0
m=9e9
for b in a:c+=b;m=min(m,abs(c+c-s))
print(m)

# Optimized solution
_,a=open(0)
*a,=list(map(int,a.split()))
s=m=sum(a)
c=0
for b in a:c+=b;m=min(m,abs(c+c-s))
print(m)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
mid = total // 2
sum_left, sum_left2 = 0, 0
seperation_i = 0
for i, l in enumerate(A[:-1]):
  sum_left += l
  if sum_left >= mid:
      seperation_i = i
      sum_left2 = sum_left - l
      break
sum_right, sum_right2 = sum(A[seperation_i + 1:]), sum(A[seperation_i:])
print((min(abs(sum_right - sum_left), abs(sum_right2 - sum_left2))))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
mid = total // 2
sum_left, sum_left2 = 0, 0
seperation_i = 0
# for i, l in enumerate(A[:-1]):
for i, l in enumerate(A):
  sum_left += l
  if sum_left >= mid:
    seperation_i = i
    sum_left2 = sum_left - l
    break
sum_right, sum_right2 = sum(A[seperation_i + 1:]), sum(A[seperation_i:])
ans = min(abs(sum_left - sum_right), abs(sum_left2 - sum_right2))
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
mid = total // 2
sum_left, sum_left2 = 0, 0
sep_idx = 0
for i, l in enumerate(A):
  sum_left += l
  if sum_left >= mid:
    sep_i = i
    sum_left2 = sum_left - l
    break
sum_right, sum_right2 = sum(A[sep_i + 1:]), sum(A[sep_i:])
print((min(abs(sum_right - sum_left), abs(sum_right2 - sum_left2))))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
mid = total // 2
sum_left, sum_left2 = 0, 0
sep_i = 0
for i, a in enumerate(A):
  sum_left += a
  if sum_left >= mid:
    sep_i = i
    sum_left2 = sum_left - a
    break
sum_right, sum_right2 = sum(A[sep_i + 1:]), sum(A[sep_i:])
print((min(abs(sum_right - sum_left), abs(sum_right2 - sum_left2))))
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
s = sum(A)
p = 10**20
t = 0
for i in range(n):
    t += A[i]
    p = min(p, abs(s-t*2))
    if 2*t > sum(A):
        break
print(p)

# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
s = sum(A)
p = 10**20
t = 0
for i in range(n):
    t += A[i]
    p = min(p, abs(s-t*2))
print(p)
# Original solution
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    st = sum(a)
    t = 0
    abs_t = 10 ** 10
    for i in range(n-1):
        t += a[i]
        st -= a[i]
        abs_t = min(abs_t, abs(st - t))
    print(abs_t)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    sa = sum(a)
    t = 0
    mt = 10 ** 20
    for v in a:
        t += v
        mt = min(mt, abs(sa - t - t))
    print(mt)


if __name__ == '__main__':
    solve()
# Original solution
N = int(eval(input()))
A = input().split()

for a in A:
    A[A.index(a)] = int(a)
# print(sum(A))

# mid = N // 2

# print(A[:mid])
# print(A[mid:])


left = A[0]
right = A[-1]

front = 1
back = 1
for _ in range(N-2):
    if left > right:
        right += A[-1 - back]
        back += 1
    else:
        left += A[front]
        front += 1
    # print(left)
    # print(right)
    # print()



# print(left)
# print(right)
# if N % 2 == 1:
#     if right > left:
#         left += A[i]
#         i += 1
#     else:
#         right += A[-1 - i]

# print(left)
# print(right)

print((abs(left-right)))


# Optimized solution
N = int(eval(input()))
# A = input().split()
A = list(map(int, input().split()))
# f = open("tmp.text")
# A = list(map(int, f.read().split()))



# left = 0
# right = N - 1
# tmp = 10**9
# while True:
#     # print(left)
#     # print(right)
#     mid = (left + right) // 2
#     # print("mid: " + str(mid))
#     lnum = A[:mid+1]
#     rnum = A[mid+1:]
#     # print(lnum)
#     # print(rnum)
#     new = abs(sum(lnum) - sum(rnum))
#     if tmp == new:
#         break
#     if tmp > new:
#         tmp = new
#     if lnum > rnum:
#         right = mid

#     # print("tmp: "+str(tmp))
#     # input()
#     if left == right:
#         break

# print(tmp)



left = A[0]
right = A[-1]

front = 1
back = 1
for _ in range(N-2):
    if left > right:
        right += A[-1 - back]
        back += 1
    else:
        left += A[front]
        front += 1

print((abs(left-right)))
# Original solution
n = int(eval(input()))
s = list(map(int,input().split()))
ans = 10**10
for i in range(n):
    ans = min(ans,(abs(sum(s[:i]) - sum(s[i:]))))
print(ans)

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

i, s = 0, 0
while True:
	s += a[i]
	i += 1
	if s >= sum(a) // 2:
		break

b = a[::-1]
j, t = 0, 0
while True:
	t += b[j]
	j += 1
	if t >= sum(a) // 2:
		break
 
print((min(s-(sum(a)-s), t-(sum(a)-t))))

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

total = sum(A)

s = 0
for a in A:
	s += a
	if 2 * s >= total:
		break

B = A[::-1]
t = 0
for b in B:
	t += b
	if 2 * t >= total:
		break

print((min(2*s-total, 2*t-total)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
x = 10 ** 10
for i in range(1, n):
    x = min(x, abs(sum(a[:i])-sum(a[i:])))
print(x)

# Optimized solution
from itertools import accumulate
n = int(eval(input()))
a = list(map(int, input().split()))
l = list(accumulate(a))
x = 10 ** 10
for i in range(n-1):
    x = min(x, abs(l[i]*2-l[-1]))
print(x)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
anslist = []
for i in range(N):
    lefts = sum(A[:i])
    rights = sum(A[i:])
    anslist.append(abs(lefts - rights))
print((min(anslist)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
anslist = []
lefts = 0
rights = sum(A)
for i in range(N):
    lefts += A[i]
    rights -= A[i]
    anslist.append(abs(lefts - rights))
print((min(anslist)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
l1 = 0

for i in range(n):
    l1 += a[i] 
    if l1> sum(a)//2:break
r1 = sum(a) - l1
l2 = l1 -a[i]
r2 = sum(a) - l2
ans = min(abs(r1-l1),abs(r2-l2))
print(ans)

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

for i in range(n):
    l1 += a[i] 
    if l1> s//2:break
r1 = s - l1
l2 = l1 -a[i]
r2 = s - l2
ans = min(abs(r1-l1),abs(r2-l2))
print(ans)
# Original solution
n =int(eval(input()))
a=list(map(int, input().split()))
m=0
s=[]
for i in range(len(a)):
    m+=a[i]
    if len(s)!=0:
        mins=min(s)
    s.append(abs(sum(a)-m*2))
    if len(s)!=1 and mins<s[i]:
        break
print(mins)

# Optimized solution
n =int(eval(input()))
a=list(map(int, input().split()))
m=0
s=[]
suma=sum(a)
for i in range(len(a)):
    m+=a[i]
    s.append(abs(suma-m*2))
print((min(s)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
m = 0
s = []
for i in range(len(a)):
    m += a[i]
    s.append(abs(sum(a) - m * 2))
print((min(s)))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
m = 0
s = []
suma = sum(a)
for i in range(len(a)):
    m += a[i]
    s.append(abs(suma - m * 2))
print((min(s)))
# Original solution
import sys
n = int(eval(input()))
a = list(map(int, input().split()))
tmp=sys.maxsize
for i in range(n+1):
    if tmp > abs(sum(a[:i])-sum(a[i:])):
        tmp = abs(sum(a[:i])-sum(a[i:]))
    else:
        print(tmp)
        exit()

# Optimized solution
import sys
n = int(eval(input()))
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
t = 0
for i in range(n):
    t += a[i]
    tmp = min(tmp,abs(s-t*2))
print(tmp)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
costs = [0 for x in range(N-1)]

mem = [0 for x in range(N-1)]
def calcsum(i):
  if mem[i] == 0:
    mem[i] == calcsum(i - 1) + A[i-1]
  return mem[i]

for i in range(1, N):
  costs[i-1] = abs(total - 2 * sum(A[:i]))
  
print((min(costs)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
total = sum(A)
costs = [0 for x in range(N-1)]
mem = [0 for x in range(N-1)]

for i in range(1, N):
  if i == 1:
    mem[i-1] = A[i-1] * 2
  else:
    mem[i-1] = mem[i-2] + A[i-1] * 2
  costs[i-1] = abs(total - mem[i-1])
  
print((min(costs)))
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
c = 0
for i in range(n):
    if (c + a[i] >= sum(a)/2):
        d = i
        break
    c += a[i]
print((min(sum(a)-2*c,2*(c+a[d])-sum(a))))


# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
c = 0
k = sum(a)
for i in range(n):
    if (c + a[i] >= k/2):
        d = i
        break
    c += a[i]
print((min(k-2*c,2*(c+a[d])-k)))
# Original solution
N=int(eval(input()))  #数値入力 「N」だけの入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

# from functools import lru_cache
# @lru_cache(maxsize=100000)

# 一度差を出してから，どんどんi-1, i+1の和で縮めていく．
def check():
    for i in range(N):
        if sum(A[:i]) == sum(A[i:]):
            return True
    return False

from functools import lru_cache
@lru_cache(maxsize=100000)
def get_dist(i):
    return abs(sum(A[:i]) - sum(A[i:]))

def check_distance():
    ret = []
    for i in range(1, N):
        tmp_a = get_dist(i)
        ret.append(tmp_a)
        # print(f"at {i}, abs:{tmp_a}")
    return min(ret)

def check_distance_2():
    ret = []
    tmp_a = abs(sum(A[:1]) - sum(A[1:]))
    # print(tmp_a)
    for i in range(1, N):
        tmp_a = abs(tmp_a - (A[i]*2))
        ret.append(tmp_a)
        # print(tmp_a)
        # print(f"at {i}, abs:{tmp_a}")
    return min(ret)

print((check_distance()))

# Optimized solution
N=int(eval(input()))  #数値入力 「N」だけの入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

# from functools import lru_cache
# @lru_cache(maxsize=100000)

# 一度差を出してから，どんどんi-1, i+1の和で縮めていく．

def check_distance():
    ret = []
    left = A[0]
    right = sum(A[1:])
    tmp_a = abs(left - right)
    ret.append(tmp_a)

    for i in range(1, N-1):
        left += A[i]
        right -= A[i]
        tmp_a = abs(left - right)
        ret.append(tmp_a)
    return min(ret)

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

aa = [0]*(n+1)

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

ans = sum(a)
for i in range(n):
    ans = min(ans,abs(sum(a)-2*aa[i]))

print(ans)

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

aa = [0]*(n+1)

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

sm = sum(a)
ans = sm
for i in range(n):
    ans = min(ans,abs(sm-2*aa[i]))

print(ans)
# Original solution
N = int(eval(input()))
arr = list(map(int, input().split()))
min_delta = sum(arr)
for i in range(1, N):
    min_delta = min(abs(sum(arr[:i]) - sum(arr[i:])), min_delta)

print(min_delta)


# Optimized solution
N = int(eval(input()))
arr = list(map(int, input().split()))
first = 0
second = sum(arr)
min_delta = second - first
for i in range(N):
    first += arr[i]
    second -= arr[i]
    min_delta = min(abs(second - first), min_delta)

print(min_delta)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
ans=20202020200
for i in range(N):
    tmp=abs(sum(A[:i])-sum(A[i:N]))
    if tmp<ans:
        ans=tmp
print(ans)

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
ans=20202020200
sum_A=0
sum_B=sum(A)
for i in range(N):
    sum_A+=A[i]
    sum_B-=A[i]
    tmp=abs(sum_A-sum_B)
    if tmp<ans:
        ans=tmp
print(ans)
# Original solution
N = int(eval(input()))

MMM = list(map(int,input().split()))
MM =list(MMM)
mini = 2020202020
for i in range(N):
  total1 = 0
  total2 = 0
  for j in range(i+1):
    
    total1 += MM[j]
  for k in range(i+1,N):
    
    total2 += MM[k]
  if abs(total1-total2)< mini:
    mini = abs(total1 -total2)
print(mini)

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

MMM = list(map(int,input().split()))
MM =list(MMM)
mini = 2020202020
list1 = []
total = 0
for i in MM:
  total+=i
  list1.append(total)
for i in list1:
  x = abs(total - 2*i)
  if mini > x:
    mini = x
print(mini)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
c=0
A1=[]
A2=[]
s1=0
s2=0
c=float("inf")
for i in range(N-1):
    A1=A[:i+1]
    A2=A[i+1:]
    s1=sum(A1)
    s2=sum(A2)
    if abs(s1-s2)<c:
        c=abs(s1-s2)
print(c)


# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
c=0
all=sum(A)
buf=all
A1=[]
A2=[]
s1=0
s2=0
c=float("inf")
for i in range(N-1):
    buf=buf-A[i]
    if c>abs((all-buf)-buf):
        c=abs((all-buf)-buf)
    else:
        break
print(c)