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

Sc = list()

for i in range(1, n):
    Sc.append(abs( sum(As[:i]) - sum(As[i:])))

print((min(Sc)))

# Optimized solution
import sys

n = int(eval(input()))
As = list(map(int, input().split()))

Sc = list()

dp = [10**9] * (n-1)
ep = [10**9] * (n-1)
s = sum(As)

if n-2 == 0:
    print((abs(As[0] - As[1])))
    sys.exit()

for i in range(n-2):
    if i == 0:
        dp[i] = As[i]
    else:
        dp[i] = dp[i-1] + As[i]
    ep[i] = abs(dp[i] - s + dp[i])


print((min(ep)))
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
S=sum(A)
print((min(abs(S-2*sum(A[i:])) for i in range(1,N))))

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

ans = 10**10
for i in range(1, N):
    a = sum(A[0:i])
    b = sum(A[i:N+1])
    ans = min(ans, abs(a - b))

print(ans)

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

ans = 10**10
for i in range(0, N-1):
    sunuke += A[i]
    arai -= A[i]
    ans = min(ans, abs(sunuke - arai))

print(ans)
# Original solution
def main():
    N = int(eval(input()))
    l = list(map(int, input().split()))
    ans = []
    sunuke = 0
    arai = sum(l)
    for i in range(N-1):
        sunuke += l[i]
        arai   -= l[i]
        ans.append(abs(sunuke-arai))
    print((min(ans)))
if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    x = 0
    for i in range(N-1):
        x += l[i]
        ans.append(abs(X-2*x))
    print((min(ans)))
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]

su = sum(A)
x = 0
mi = 1e15
for a in A[:-1]:
    x += a
    mi = min(mi, abs(su - 2 * x))
print(mi)

# Optimized solution
from itertools import accumulate

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

*B, su = list(accumulate(A))
print((min(abs(su - 2 * b) for b in B)))
# Original solution
n=int(eval(input()))
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
for i in range(1,n):
  ans=abs(2*sum(a[:i])-suma)
  if ans < minans:
    minans = ans
    
print(minans)


# Optimized solution
n=int(eval(input()))
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
#print(minans)

mydata=0
for i in range(0,n-1):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)
# Original solution
# coding: utf-8
# Your code here!
import math
N = int(eval(input()))
lst = list(map(int,input().split()))
ans = float('inf')
for i in range(N-1):
    #print(sum(lst[:i+1]) , sum(lst[i+1:]))
    ans = min(ans,math.fabs(sum(lst[:i+1]) - sum(lst[i+1:])))
print((int(ans)))

# Optimized solution
# coding: utf-8
# Your code here!
import math
N = int(eval(input()))
lst = list(map(int,input().split()))
x = lst[0]
y = sum(lst[1:])
ans = abs(y - x)
for i in range(1,N-1):
    x+=lst[i]
    y-=lst[i]
    ans = min(ans,abs(x-y))
print(ans)
# Original solution
#Python

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


b=[]
for i in range(N-1):
	i=i+1
	#print "x::"+str(sum(a[:i]))
	#print "sum-2x::"+str( abs( sum(a) - sum(a[:i])*2 ) )
	b.append( abs( sum(a) - sum(a[:i])*2 ) )

#print b
print(min(b))


# Optimized solution
#Python

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

b=[]
ans=0
sum=sum(a)

x=0
for i in range(N-1):
	x+=a[i]
	#print "x::"+str(x)
	if i==0:
		ans= abs( sum - x*2 )
	if ans>abs( sum - x*2 ):
		ans= abs( sum - x*2 )
	#print "ans::"+str(ans)

print(ans)
# Original solution
from itertools import accumulate as acc
eval(input())
S=tuple(acc(list(map(int,input().split()))))
print((min(abs(S[-1]-2*x)for x in S[:-1])))

# Optimized solution
from itertools import accumulate as acc
eval(input())
s=list(acc(list(map(int,input().split()))));S=s.pop()
print((min(abs(S-2*x)for x in s)))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x-y==0:
  ans = 0
else:
  ans = abs(x-y)

for i in range(2,N):
  s = a[:i]
  t = a[i:]
  x = sum(s)
  y = sum(t)
  if x-y==0:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x==y:
  ans = 0
else:
  ans = abs(x-y)

for i in range(1,N-1):
  x += a[i]
  y -= a[i]
  if x==y:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = [0]
for i in range(N):
    B.append(B[i]+A[i])
dmin = 10**15
for i in range(1,N):
    dmin = min(dmin,abs(B[N]-2*B[i]))
print(dmin)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
cmin = 10**15
for i in range(1,N):
    cmin = min(cmin,abs(2*B[i]-B[N]))
print(cmin)
# Original solution
def main():
  n=int(eval(input()))
  a=list(map(int,input().split()))
  ans=float('inf')
  for i in range(1,n):
    ans=min(ans,abs(sum(a[i:])-sum(a[:i])))
  print(ans) 
if __name__=='__main__':
  main()

# Optimized solution
def main():
  n=int(eval(input()))
  a=list(map(int,input().split()))
  ans,s,x=abs(sum(a)-2*a[0]),sum(a),a[0]
  for i in range(1,n-1):
    x+=a[i]
    ans=min(ans,abs(s-2*x))
  print(ans)
if __name__=='__main__':
  main()
# Original solution
# encoding:utf-8

def main():
	N = int(eval(input()))
	cards = list(map(int, input().split()))

	if N == 2:
		print((abs(cards[0] - cards[1])))
	else:
		print((min([abs(calcDif(cards, x)) for x in range(1, N - 1)])))


def calcDif(cards, k):
	# k >= 1
	#print(k)
	x = cards[:k]
	y = cards[k:len(cards)]
	return(sum(x) - sum(y))

if __name__ == '__main__':
	main()

# Optimized solution
# encoding:utf-8

def main():
	N = int(eval(input()))
	cards = list(map(int, input().split()))

	x = cards[0]
	y = sum(cards[1:])
	i = 1
	val = abs(x - y)

	while i < len(cards) - 1:
		x += cards[i]
		y += -cards[i]
		temp = abs(x - y)
		
		if temp == 0:
			val = 0
			break
		if temp < val:
			val = temp

		i += 1

	print(val)

if __name__ == '__main__':
	main()
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))

mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
for i in range(N-1):
    s1 = sum(a[0:i + 1])
    s2 = sum(a[i+1:])
    mindiff = min(mindiff, abs(s1 - s2))
    
print(mindiff)

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

mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
s1 = 0
s2 = sum(a)
for i in range(N-1):
    s1 += a[i]
    s2 -= a[i]
    mindiff = min(mindiff, abs(s1 - s2))
    
print(mindiff)
# Original solution
#!/usr/bin/env python
n = int(eval(input()))
a = list(map(int, input().split()))
ans = float('inf')
for i in range(1, n):
    ans = min(ans, abs(sum(a[:i])-sum(a[i:])))
print((int(ans)))

# Optimized solution
#!/usr/bin/env python
n = int(eval(input()))
a = list(map(int, input().split()))
total = sum(a)
ans = float('inf')
tmp = 0
for i in range(n):
    tmp += a[i]
    if i==n-1:
        continue
    ans = min(ans, abs(tmp-(total-tmp)))
print((int(ans)))
# Original solution
N = int(eval(input()))
card = list(map(int,input().split(' ')))

sum_card = sum(card)
dif_list = []
min_value = 1000000000
for i in range(1,N,1):
  sunuke = sum(card[:i])
  if abs(sum_card/2 - sunuke) < min_value:
    min_value = abs(sum_card/2 - sunuke)
  
print((int(2*min_value)))

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

sum_card = sum(card)
min_value = 10000000000
sunuke = 0
for i in range(0,N-1,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print((int(min_value)))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))

ans = float('inf')
for i in range(1, N):
    ans = min(abs(sum(a[:i])-sum(a[i:])), ans)

print(ans)

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

arai = sum(a)-a[0]
sunuke = a[0]
ans = abs(sunuke-arai)
for i in a[1:-1]:
    sunuke += i
    arai -= i
    ans = min(abs(sunuke-arai), ans)

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

c = []
for i in range(N-1):
	b = a[0:i+1]
	c.append(abs(sum(a)-2*sum(b)))

print((min(c)))

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

c = [2*a[0]-sum(a)]
d = [abs(c[0])]
for i in range(N-2):
	c.append(c[i]+2*a[i+1])
	d.append(abs(c[i+1]))

print((min(d)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
min_v = float('inf')
for i in range(1,n):
    tmp1 = a[:i]
    tmp2 = a[i:]
    min_v = min(abs(sum(tmp1) - sum(tmp2)), min_v)

print(min_v)

# Optimized solution
n = int(eval(input()))
l = list(map(int,input().split()))
x = 0
y = sum(l)
xy = [10**15]*n
for i in range(n-1):
    x += l[i]
    y -= l[i]
    xy[i] = abs(x-y)
print((min(xy)))
# Original solution
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10**10
x = 0
for i in range(N-1):
    x+=A[i]
    ans = min(ans, abs(sum(A)-2*x))
print(ans)

# Optimized solution
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
Asum = sum(A)
ans = 10**10
x = 0
for i in range(N-1):
    x+=A[i]
    ans = min(ans, abs(Asum-2*x))
print(ans)
# Original solution
n = int(eval(input()))
dec = list(map(int, input().split()))
diff = []
for i in range(1, n):
    diff.append(abs(sum(dec[:i])-sum(dec[i:])))
print((min(diff)))

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

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

# Optimized solution
n,x,*a,b=list(map(int,open(0).read().split()))
y=sum(a)+b
z=abs(x-y)
for i in a:x+=i;y-=i;z=min(z,abs(x-y))
print(z)
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
x = sum(a)
answer = abs(x-2*a[0])
for i in range(1,n):
	y = sum(a[i:])
	if answer>abs(x-2*y):
		answer = abs(x-2*y)
print(answer)

# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
x,y = a[0],sum(a)-a[0]
answer = abs(x-y)
for i in range(1,n-1):
	x += a[i]
	y -= a[i]
	if answer > abs(x-y):
		answer = abs(x-y)
print(answer)
# Original solution
import math
ans = math.inf
n = int(eval(input()))
c = list(map(int, input().split()))
s, a = 0, 0
for i in range(n - 1):
    s = sum(c[:i+1])
    a = sum(c[i+1:])
    ans = min(ans, abs(s-a))
print(ans)


# Optimized solution
import math
ans = math.inf
n = int(eval(input()))
c = list(map(int, input().split()))
acm = [0]*(n+1)
for i, v in enumerate(c, 1):
    acm[i] += acm[i-1] + v

s, a = 0, acm[n]
for i in range(1, n):
    s = acm[i]
    ans = min(ans, abs((a-s)-s))

print(ans)
# Original solution
n= int(eval(input()))
card = input().split(' ')
card = [int(s) for s in card]
min_s = 1000000000000
for i in range(n -1):
    if abs(sum(card[:i+1]) - sum(card[i+1:])) < min_s:
        min_s= abs(sum(card[:i+1]) - sum(card[i+1:]))
    
print(min_s)

# Optimized solution
n= int(eval(input()))
card = input().split(' ')
card = [int(s) for s in card]
min_s = 20000000000
sum1 = sum(card[:1])
sum2 = sum(card[1:])
for i in range(n - 1):
    dif  = abs(sum1-sum2)

    if dif  < min_s:
        min_s = dif
    sum1 += card[i+1]
    sum2 = sum2 - card[i+1]
print(min_s)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))

ans = 2*10**9

allsum = sum(a)

for n in range(1,N):
  ans_candidate = abs(2*sum(a[:n])- allsum)
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)


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

ans = 2*10**9
allsum = sum(a)
snukesum = 0

for n in range(1,N):
  snukesum += a[n-1]
  ans_candidate = abs(2*snukesum- allsum)
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)
# Original solution
N = int(eval(input()))
src = list(map(int, input().split()))

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

ans = float('inf')
for i in range(N-1):
    a = s[i+1]
    b = s[-1] - s[i+1]
    df = abs(a-b)
    ans = min(ans, df)
print(ans)


# Optimized solution
N = int(eval(input()))
src = list(map(int,input().split()))
s = sum(src)
ans = float('inf')
tmp = 0
for i in range(N-1):
    tmp += src[i]
    rem = s - tmp
    ans = min(ans, abs(tmp - rem))
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)

ans = 10**20
for i in range(1,N):
    x = cums[i]
    y = cums[-1] - cums[i]
    ans = min(ans, abs(x-y))
print(ans)

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

    sum_a = sum(a)
    min_diff = float('inf')
    for i in range(1,N):
        if min_diff > abs(sum_a-2 * sum(a[i:])):
            min_diff = abs(sum_a-2 * sum(a[i:]))

    print(min_diff)

main()

# Optimized solution
def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in range(N-1):
        sum_first += a[i]
        if min_diff > abs(sum_a - 2 * sum_first):
            min_diff = abs(sum_a - 2 * sum_first)

    print(min_diff)

main()
# Original solution
n = int(eval(input()))
arr = input().split()
x = 0
y = 0
for i in range(n):
    arr[i] = int(arr[i])
min_xy = abs(arr[0] - sum(arr[1:]))
for i in range(1,n):
    x = sum(arr[:i])
    y = sum(arr[i:])
    if min_xy > abs(x - y):
        min_xy = abs(x - y)
print(min_xy)



# Optimized solution
n = int(eval(input()))
arr = list(map(int,input().split()))
sum_arr = sum(arr)
ans=[]
x = 0
for i in range(n-1):
    x += arr[i]
    y = sum_arr - x
    ans.append(abs(x - y))
print((min(ans)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

sum_a = sum(a)

lis = [sum_a]

for i in range(n-1):
    lis.append(abs(sum_a - 2 * sum(a[:i+1])))

print((min(lis[1:])))

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

s = s[1:]

ma = s[-1]

ans = 10 ** 18


for i in s[:-1]:
    ans = min(ans, abs(ma-2*i))

print(ans)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i]+A[i]
INF = 10**18
ans = INF
for R in range(1, n):
    ans = min(ans, abs((S[R]-S[0])-(S[n]-S[R])))
print(ans)


# Optimized solution
n = int(eval(input()))
A = list(map(int, input().split()))
sum_A = sum(A)
INF = 10**18
ans = INF
X = 0
for a in A[:-1]:
    X += a
    ans = min(ans, abs(2*X-sum_A))
print(ans)
# Original solution
N = int(eval(input()))
I = list(map(int, input().split()))
minX = 10000000000
end = I.pop() 
for i in range(len(I)):
  minX = min(minX, abs(sum(I) - end ) )
  end += I.pop() 
  
print(minX)

# Optimized solution
N = int(eval(input()))
I = list(map(int, input().split()))
minX = 10000000000
end = I.pop()
sumI = sum(I)
for i in range(len(I)):
  minX = min(minX, abs(sumI - end ) )
  popped = I.pop()
  sumI -= popped
  end += popped
  
print(minX)
# Original solution
# vim: set fileencoding=utf-8 :
n = int(input())
a = list(map(int, input().split()))

diff = None
min_diff = 999999999999999999

for i in range(n - 1):
    x = sum(a[0:i + 1])
    y = sum(a[i + 1:])
    diff = abs(x - y)
    if diff < min_diff:
        min_diff = diff

print(min_diff)


# Optimized solution
# vim: set fileencoding=utf-8 :
n = int(input())
a = list(map(int, input().split()))

diff = None
min_diff = 999999999999999999
x = 0
y = sum(a)

for i in range(n - 1):
    x += a[i]
    y -= a[i]
    diff = abs(x - y)
    if diff < min_diff:
        min_diff = diff

print(min_diff)
# Original solution
def main():
    N, *a = list(map(int, open(0).read().split()))
    print((min(abs(2 * sum(a[:i]) - sum(a)) for i in range(1, N))))
    return


main()


# Optimized solution
INF = float('inf')


def main():
    N, *a = list(map(int, open(0).read().split()))
    ans = INF
    tmp = 0
    total = sum(a)
    for i in range(N - 1):
        tmp += a[i]
        ans = min(ans, abs(2 * tmp - total))
    print(ans)
    return


main()
# Original solution
from itertools import accumulate


def main():
    N, *a = list(map(int, open(0).read().split()))
    a = tuple(accumulate(a))
    print((min(abs(2 * a[i] - a[-1]) for i in range(N - 1))))
    return


main()


# Optimized solution
from itertools import accumulate


def main():
    N, *a = list(map(int, open(0).read().split()))
    a = tuple(accumulate(a))
    total = a[-1]
    print((min(abs(2 * a[i] - total) for i in range(N - 1))))
    return


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

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

l.reverse()

x = 0

sum_x = []

for i in range(n-1):
    x += l[i]
    sum_x.append(x)

sum_y = [sum(l)]*(n-1)

for i in range(n-1):
    sum_y[i] -= sum_x[i]
    
abs_xy = []

for i in range(n-1):
    abs_xy.append(abs(sum_x[i]-sum_y[i]))

print((min(abs_xy)))

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

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

l.reverse()

x = 0
sum_x = []
sum_y = [sum(l)]*(n-1)
abs_xy = []

for i in range(n-1):
    x += l[i]
    sum_x.append(x)
    sum_y[i] -= sum_x[i]
    abs_xy.append(abs(sum_x[i]-sum_y[i]))


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

ans=[]

for i in range(1,n):
    snuke=sum(a[0:i])
    raccoon=sum(a)-snuke
    ans.append(abs(snuke-raccoon))

print((min(ans)))


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

ans=[]
snuke=0

for i in range(n-1):
    snuke+=a[i]
    ans.append(abs(X-2*snuke))

print((min(ans)))
# Original solution
N = int(eval(input()))
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
for i in range(N-1):
    b.append(abs(2*sum(a[:i+1])-sum_a))
print((min(b)))


# Optimized solution
N = int(eval(input()))
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
c = 0
for i in range(N-1):
    c += a[i]
    b.append(abs(2*c-sum_a))
print((min(b)))
# Original solution
def splitting_pile():
	n = int(input())
	nums = list(map(int, input().split(" ")))
	ans = abs(sum(nums[:1])-sum(nums[1:]))
	for i in range(1, n):
		ans = min(ans, abs(sum(nums[:i])-sum(nums[i:])))
	print(ans)


if __name__ == "__main__":
	splitting_pile()

# Optimized solution
def splitting_pile_2():
	n = int(input())
	nums = list(map(int, input().split(" ")))
	total_sum = sum(nums)
	left_sum = nums[0]
	ans = abs(total_sum-left_sum*2)

	for i in range(1, n-1):
		left_sum = left_sum + nums[i]
		ans = min(ans, abs(total_sum-left_sum*2))
	print(ans)


if __name__ == "__main__":
	splitting_pile_2()
# Original solution
N = int(eval(input()))

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

min_a = 999999999999999
for i in range(1, len(a)):
    cal = abs(sum(a[:i]) - sum(a[i:]))
    if cal < min_a:
        min_a = cal
print(min_a)

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

su = sum(a)
diff = 1e10
cc = 0

for i in range(len(a)-1):
    cc += a[i]
    diff = min(diff, abs(su-2*cc))
print(diff)
# Original solution
n = int(eval(input()))
num_list = list(map(int, input().split()))
dis = n * 10**9

for i in range(1,n):
    a = sum(num_list[:i])
    b = sum(num_list[i:])
    if abs(a-b) < dis:
        dis = abs(a-b)

print(dis)


# Optimized solution
n = int(eval(input()))
num_list = list(map(int, input().split()))
total = sum(num_list)
dis = []
a=0

for i in range(n-1):
    a += num_list[i]
    b = total - a
    dis.append(abs(a-b))

print((min(dis)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
cumsum = [a[0]]
for i in range(len(a)-1):
  cumsum.append(cumsum[i] + a[i+1])

min = float('inf')
for i in range(len(cumsum)-1):
  f1 = cumsum[i]
  f2 = cumsum[-1] - cumsum[i]
  d = abs(f1 - f2)
  if min >  d:
    min = d

print(min)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
sa = a[:]
for i in range(N-1):
  sa[i+1] += sa[i]

diff = float('inf')
for i in range(N-1):
  if abs(sa[i] - (sa[-1] - sa[i])) < diff:
    diff = abs(sa[i] - (sa[-1] - sa[i]))

print(diff)
# Original solution
n=int(eval(input()))
a=[int(i) for i in input().split()]
m=float("inf") 

for i in range(1,n):
  m = min(abs(sum(a[:i]) - sum(a[i:])),m)
print((int(m)))


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

x=a[0]
y=sum(a[1:])
m=abs(x - y)

i=1

while i < n-1:
  x+=a[i]
  y-=a[i]
  m = min(abs(x - y),m)
  i+=1
print(m)
# Original solution
# Splitting Pile
N = int(eval(input()))
a = list(map(int, input().split()))

s = [abs(sum(a[:i+1])-sum(a[i+1:])) for i in range(N-2)] 
if len(a)==2:
    print((abs(a[0]-a[1])))
else:
    print((min(s)))

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

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
x = sum(a)
t = sum(a)
difference = []
for i in range(n-1):
	x = x - a[i]
	difference.append(abs(t-2*x))
print((min(difference)))
# Original solution
# C - pushpush
N = int(eval(input()))
a = list(map(int,input().split()))

S = sum(a)
lst = [0]*N
x = 0
y = 0

for i in range(N):
    x = sum(a[0:i])
    y = S - x
    lst[i] = abs(x-y)
lst.pop(0)

ans = min(lst)
print(ans)


# Optimized solution
# C - Splitting Pile
N = int(eval(input()))
a = list(map(int,input().split()))

lst = [0]*(N-1)
x = [a[0]]*(N-1)
y = [sum(a)-a[0]]*(N-1)
lst[0] = abs(x[0]-y[0])

for i in range(1,N-1):
    x[i] = x[i-1]+a[i] 
    y[i] = y[i-1]-a[i]
    lst[i] = abs(x[i]-y[i])
"""
print(x)
print(y)
print(lst)
"""
ans = min(lst)
print(ans)
# Original solution

def 解():
    iN = int(eval(input()))
    aA = [int(_) for _ in input().split()]
    #itertools をつかわず 累積和でやってみると？
    aAc = [0]*iN
    aAc[0] = aA[0]
    for i in range(1,iN):
        aAc[i] = aAc[i-1] + aA[i]
    iD = aAc[-1]
    minDiff = 10**9 *2
    for i in range(iN-1):
        minDiff = min(minDiff,abs(iD-2*aAc[i]))
    print(minDiff)
解()


# Optimized solution
def 解():
    iN = int(eval(input()))
    aA = [int(_) for _ in input().split()]

    iD = sum(aA)
    iF = 0
    minDiff = 10**9 * 2
    for a in aA[:-1] :
        iF += a
        thisDiff = abs(iD - 2*iF)
        minDiff = min(minDiff , thisDiff)
    print(minDiff)
解()
# Original solution
def 解():
    iN = int(eval(input()))
    aA = [int(_) for _ in input().split()]

    iD = sum(aA)
    iF = 0
    minDiff = 10**9 * 2
    for a in aA[:-1] :
        iF += a
        thisDiff = abs(iD - 2*iF)
        minDiff = min(minDiff , thisDiff)
    print(minDiff)
解()


# Optimized solution
def 解():
    iN = int(eval(input()))
    aA = [int(_) for _ in input().split()]
    aDiff  = [0]*(iN-1)
    iD = sum(aA)
    iF = 0
    for i in range(iN-1):
        iF += aA[i]
        aDiff[i] = abs(iD - 2*iF)
    print((min(aDiff)))
解()