CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))
b=[]
a=list(map(int,input().split()))
k=a[0]
for i in range(n-1):
	b.append(abs(sum(a)-k*2))
	k+=a[i+1]
print((min(b)))


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

for i in range(N):
  Sf.append(Sf[i]+C[i])
#print(Sf)

C=C[::-1]
Sb=[0]
for i in range(N):
  Sb.append(Sb[i]+C[i])
Sb=Sb[::-1]
#print(Sb)

ans=10**10
for i in range(1,N):
  ans=min(ans,abs(Sf[i]-Sb[i]))
print(ans)

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

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

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

answer = 10 ** 15
for i in range(N - 1):
  answer = min(answer, abs(Sf[i] - Sb[i + 1]))
  
print(answer)
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))

cum_sum = [sum(A[:i+1]) for i in range(len(A))]
b = cum_sum[-1]

ans = float("inf")

for a in cum_sum[:-1]:
    ans = min(ans, abs(2 * a - b))

print(ans)


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

ans = float("inf")
cum_sum = 0

for a in A[:-1]:
    cum_sum += a
    ans = min(ans, abs(2 * cum_sum - b))

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

print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10 ** 10
total = sum(a)
tmp = 0
for i in range(N - 1):
    tmp += a[i]
    ans = min(ans, abs(total - (2 * tmp)))

print(ans)
# Original solution
N, = list(map(int, input().split()))
a = list(map(int, input().split()))
sl = [0]*N
sl[0] = a[0]
for i in range(N-1):
  sl[i+1] = sl[i]+a[i+1]
sr = [0]*N
sr[N-1] = a[N-1]
for i in range(N-1,0,-1):
  sr[i-1] = sr[i]+a[i-1]
r = abs(sl[0]-sr[1])
for i in range(1, N-1):
  r = min(r, abs(sl[i]-sr[i+1]))
print(r)

# Optimized solution
N, = list(map(int, input().split()))
a = list(map(int, input().split()))
x = a[0]
y = sum(a) - a[0]
r = abs(x-y)
for ai in a[1:N-1]:
  x += ai
  y -= ai
  r = min(r, abs(x-y))
print(r)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
X = sum(a)
ans = abs(X - 2*a[0])
for i in range(2, N):
    tmp = abs(X-2*sum(a[:i]))
    if (ans > tmp):
        ans = tmp
print(ans)


# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
X = sum(a)
x = a[0]
ans = abs(X - 2*x)
for i in range(1, N-1):
    x += a[i]
    tmp = abs(X-2*x)
    if (ans > tmp):
        ans = tmp
print(ans)
# Original solution
N = int(input())
a = list(map(int, input().split()))

diff = [abs(sum(a[select:])-sum(a[:select])) for select in range(1,N)]
print(min(diff))

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

sum1 = a[0]
sum2 = sum(a[1:])
diff = [abs(sum1-sum2)]
for i in range(1,N-1):
  sum1 += a[i]
  sum2 -= a[i]
  diff.append(abs(sum1-sum2))

# diff = [abs(sum(a[select:])-sum(a[:select])) for select in range(1,N)]
print(min(diff))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

sm = sum(a)
sn = a[0]
ar = sm - a[0]
ans = abs(sn - ar)

for i in range(1,len(a)-1):
    sn += a[i]
    ar -= a[i]
    ans = min(ans,abs(sn-ar))

print(ans)

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

    sm = sum(a)
    sn = a[0]
    ar = sm - a[0]
    ans = abs(sn - ar)

    for i in range(1,len(a)-1):
        sn += a[i]
        ar -= a[i]
        ans = min(ans,abs(sn-ar))

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
a = input().split()
sum0 = 0

for i in range(N):
  a[i] = int(a[i])
  sum0 += a[i]

for i in range(N-1):
  if(i == 0):
   b = a[0]
   min = abs(2*b-sum0)
  elif(1<=i<=int(N/2)-1):
   b = a[:i+1]
   #print(b)
   tmp = abs(2*sum(b)-sum0)
   if(min > tmp):
      min = tmp
  else:
   b = a[i+1:]
   #print(b)
   tmp = abs(2*sum(b)-sum0)
   if(min > tmp):
      min = tmp
  #print(min)
print(min)
 

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

min_dif = float('inf')
s1 = 0
for i in range(N):
  if(i != N-1):
   s1 += A[i]
   s2 = sum_all - s1
   tmp_dif = abs(s1 - s2)
   min_dif = min(min_dif,tmp_dif)
print(min_dif)
# Original solution
from collections import deque

if(__name__ == "__main__"):
    N = int(eval(input()))
    a = [int(i) for i in input().split()]
    #print(a,b)
    
    #print(maxlist)
    sunuke = a[:1]
    arai = a[1:]
    darai = deque(arai)
    #print(sunuke)
    #print(darai)
    distmin = abs(sum(sunuke) - sum(darai))
    
    for i in range(1,N-1):
        sunuke.append(a[i])
        darai.popleft()
        #print(sunuke)
        #print(darai)
        dist = abs(sum(sunuke) - sum(darai))
        if(distmin > dist):
            distmin = dist
    
    print(distmin)

# Optimized solution
if(__name__ == "__main__"):
    N = int(eval(input()))
    a = [int(i) for i in input().split()]
    #print(a,b)
    
    #print(maxlist)
    sumsunuke = a[0]
    arai = a[1:]
    sumarai = sum(arai)
    #darai = deque(arai)
    #print(sumsunuke)
    #print(sumarai)
    distmin = abs(sumsunuke - sumarai)
    
    for i in range(1,N-1):
        sumsunuke += a[i]
        sumarai -= a[i]
        #print(sunuke)
        #print(darai)
        dist = abs(sumsunuke - sumarai)
        if(distmin > dist):
            distmin = dist
    
    print(distmin)
# Original solution
n, *a = list(map(int, open(0).read().split()))
s = sum(a)
print((min(abs(s - sum(a[:i])*2) for i in range(1, n))))

# Optimized solution
from itertools import*
_, *d = list(map(int, open(0).read().split()))
*a, s = list(accumulate(d))
print((min(abs(s - x*2) for x in a)))
# Original solution
from itertools import*;*a,s=list(accumulate(list(map(int,open(0).read().split()[1:]))));print((min(abs(s-x*2)for x in a)))

# Optimized solution
from itertools import*;eval(input());*a,s=accumulate(list(map(int,input().split())));print((min(abs(s-x*2)for x in a)))
# Original solution
n = int(eval(input()))
a =[int(i)  for i in input().split()]
b = sum(a) // 2
z = sum(a)
ans = 10**20

for i in range(1,n):
    c = sum(a[:i])
    d = z - c
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

# Optimized solution
n = int(eval(input()))
a =[int(i)  for i in input().split()]
z = sum(a)
ans = 10**20
c = 0

for i in range(n-1):
    c += a[i]
    z -= a[i]
    if abs(c-z) < ans:
        ans = abs(c-z)
    
print(ans)
# Original solution
N=int(eval(input()))
a=list(map(int,input().split()))
List=[]
for i in range(1,N):
  x=sum(a[0:i])
  y=sum(a[i:N])
  List.append(abs(x-y))
print((min(List)))

# Optimized solution
N=int(eval(input()))
a=list(map(int,input().split()))
List=[]
x1=a[0]
y1=sum(a[1:N])
List.append(abs(x1-y1))
for i in range(1,N-1):
  x1+=a[i]
  y1-=a[i]
  List.append(abs(x1-y1))
print((min(List)))
# Original solution
N = int(eval(input()))
L = list(map(int, input().split()))
tmp = 10 ** 12

for i in range(1,N):
    if abs(sum(L[:i]) - sum(L[i:])) < tmp:
        tmp =  abs(sum(L[:i]) - sum(L[i:]))
print(tmp)

# Optimized solution
N = int(eval(input()))
L = list(map(int, input().split()))
tmp = 10 ** 12
after = sum(L)
before = 0
for i in range(N-1):
    before += L[i]
    after -= L[i]
    if abs(before -after) < tmp:
        tmp = abs(before -after)
print(tmp)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
total = sum(a)
ans = float('inf')
for i in range(1,N):
    ans = min(abs(total-2*sum(a[:i])),ans)
print (ans)


# Optimized solution
N = int(eval(input()))
a = list(map(int,input().split()))
total = sum(a)
ans = float('inf')
x = 0
for i in range(N-1):
    x += a[i]
    ans = min(abs(total-2*x),ans)
print (ans)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10000000000
total = sum(a)
for i in range(1, N):
    sunuke = a[:i]
    Sum = sum(sunuke)
    if abs(Sum - (total - Sum)) <= ans:
        ans = abs(Sum - (total - Sum))
print(ans)


# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
ans = 10000000000
total = sum(a)
sunuke = 0
for i in range(N-1):
    sunuke += a[i]
    dif = abs(2 * sunuke - total)
    if dif <= ans:
        ans = dif
print(ans)
# Original solution
if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int, input().split()))

    ans = 10**10
    for i in range(1, n):
        g1 = a[0:i]
        g2 = a[i:n]
        tmp = abs(sum(g1) - sum(g2))
        if tmp < ans:
            ans = tmp

    print(ans)


# Optimized solution
if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int, input().split()))

    g1 = a[0]
    g2 = sum(a[1:n])
    ans = abs(g1 - g2)
    if n > 2:
        for i in range(1, n-1):
            g1 += a[i]
            g2 -= a[i]
            tmp = abs(g1 - g2)
            if tmp < ans:
                ans = tmp

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

a_sum = sum(a_list)
min_num = float("inf")

for i in range(1, N):
    x = sum(a_list[:i])
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)

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

a_sum = sum(a_list)
min_num = float("inf")
r = []

for i in range(1, N):
    if len(r) == 0:
        r.append(a_list[0])
    else:
        r.append(r[i-2] + a_list[i-1])

    x = r[i-1]
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

X = sum(a)
x = list(sum(a[:i+1]) for i in range(n))
ans = min(list(abs(X-2*x[i]) for i in range(n-1)))

print(ans)

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

X = sum(a)
x =[a[0]]
for i in range(n-1):
	x.append(x[i]+a[i+1])
ans = min(list(abs(X-2*x[i]) for i in range(n-1)))

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

S = sum(A)
x = 0
ans = float('inf')
for i in range(N):
    x += A[i]
    if i < N - 1:
        ans = min(ans, abs(S - x * 2))
print(ans)

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

S = sum(A)
x = 0
ans = float('inf')
for i in range(N - 1):
    x += A[i]
    ans = min(ans, abs(S - x * 2))
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
z = sum(a)
ln = []
for i in range(1, n):
    ln.append(abs(z - 2 * sum(a[0: i])))
print((min(ln)))

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

# Optimized solution
N=int(eval(input()))
an=list(map(int,input().split()))
s=sum(an)
b = an[0]

l=[]
a = abs(s-2*b)
for i in range(1,N-1):
    b = b + an[i]
    a=min(a,abs(s-2*b))
print(a)
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:14:43 2020

@author: H_Hoshigi
"""

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

sunuke = a_list[0]
araiguma = sum(a_list[1:])
min_difference = abs(sunuke - araiguma)

for i in range(1,N-1):
    sunuke += a_list[i]
    araiguma -= a_list[i]
    min_difference = min(min_difference,
                         abs(sunuke - araiguma))

print(min_difference)


# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:29:09 2020

@author: H_Hoshigi
"""
import sys

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


#sunuke = a_list[0]
#araiguma = sum(a_list[1:])
#min_difference = abs(sunuke - araiguma)
sunuke = 0
sum_a = sum(a_list)

min_difference = sys.maxsize
#abs(sunuke - araiguma)は、abs(sum(a_list)-sunuke*2)として求められる。

#range(1,N-1)ではなく、最初の一枚目から比較する形にした。
for i in range(N-1):
    sunuke += a_list[i]
    #araiguma -= a_list[i]
    min_difference = min(min_difference,
                         abs(sum_a - 2*sunuke))

print(min_difference)
# Original solution
n=int(eval(input()))
a=[int(i) for i in input().split()]
x=0
y=0
l=float("inf")
for i in range(n-1):
  x+=a[i]
  y=sum(a)-x
  l=min(l,abs(x-y))
print(l)

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

ans = []
for x in range(1, n):
  y = n - x
  dis = abs(sum(a[:x]) - sum(a[x:]))
  ans.append(dis)

print((min(ans)))

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

total = sum(a)
ans = []
for x in range(n-1):
  total -= 2*a[x]
  ans.append(abs(total))

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

left = [0] * N
right = [0] * N

left[0] = a[0]
right[-1] = a[-1]
for i in range(1, N):
    left[i] = a[i] + left[i-1]
for i in range(N-2, -1, -1):
    right[i] = a[i] + right[i+1]

# print(left)
# print(right)
ans = abs(left[0] - right[1])
for i in range(1, N-1):
    ans = min(ans, abs(left[i] - right[i+1]))
print(ans)


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

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

    left = [0] * N
    left[0] = a[0]
    for i in range(1, N):
        left[i] = left[i-1] + a[i]
    # print(left)
    ans = abs(left[-1] - 2 * left[0])
    for i in range(1, N-1):
        ans = min(ans, abs(left[-1] - 2 * left[i]))
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))

    ans = float("inf")
    S = sum(A)
    if N == 2:
        ans = abs(A[0]-A[1])
    else:
        for i in range(1, N-1):
            t = sum(A[:i])
            ans = min(ans, abs(S-2*t))
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


# Optimized solution
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))

    ans = float("inf")
    S = sum(A)
    T = []
    T.append(A[0])
    for i in range(1, N):
        T.append(T[i-1]+A[i])

    if N == 2:
        ans = abs(A[0]-A[1])
    else:
        for i in range(1, N-1):
            ans = min(ans, abs(S-2*T[i]))
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()
# Original solution
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))

    ans = float("inf")
    S = sum(A)
    T = []
    T.append(A[0])
    for i in range(1, N):
        T.append(T[i-1]+A[i])

    if N == 2:
        ans = abs(A[0]-A[1])
    else:
        for i in range(1, N-1):
            ans = min(ans, abs(S-2*T[i]))
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


# Optimized solution
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))

    ans = float("inf")
    S = sum(A)
    T = []
    T.append(A[0])
    for i in range(1, N-1):
        T.append(T[i-1]+A[i])
    for t in T:
        ans = min(ans, abs(S-2*t))

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()
# Original solution
def splittingplie(n , a):

    ans = 100000000000000

    for i in range(1 , n):
        rldifference = abs(sum(a[:i]) - sum(a[i:]))
        ans = min(ans , rldifference)
    return ans

def main():
    n = int(eval(input()))
    a = list(map(int , input().split()))
    print((splittingplie(n , a)))

if __name__ == '__main__':
    main()

# Optimized solution
def splittingplie(n , a):

    ans = 10**18
    allsum = int(sum(a))
    asum = 0

    for i in range(n - 1):
        asum += a[i]
        rldifference = abs(allsum - asum*2)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(eval(input()))
    a = list(map(int , input().split()))
    print((splittingplie(n , a)))

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
A = list(map(int, input().split()))
sunuke = sum(A)
arai = 0

f_inf = float("inf")
res = f_inf
for i in range(n - 1):
    arai += A[i]
    sunuke -= A[i]
    res = min(res, abs(sunuke - arai))
print(res)


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(eval(input()))
    A = list(map(int, input().split()))[::-1]

    snuke = sum(A)
    arai = 0

    res = f_inf
    for i in range(n - 1):
        snuke -= A[i]
        arai += A[i]
        res = min(res, abs(snuke - arai))

    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
ans  =2*10**9
for i in range(1, N):
    ans = min(ans, abs(sum(a[:i])-sum(a[i:])))
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
sunu = sum(a)
arai = 0
ans = 2*10**9
for i in range(n-1):
  sunu -= a[i]
  arai +=  a[i]
  ans = min(ans,abs(sunu-arai))
  
print(ans)
# Original solution
import itertools
N = int(eval(input()))
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = sum(a)
ans = 10**100
for i in range(N-1):
    ans = min(ans,abs(sum(a[:i+1])*2-b))
print(ans)

# Optimized solution
import itertools
N = int(eval(input()))
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = sum(a)
ans = 10**100
for i in range(N-1):
    ans = min(ans,abs(ruiseki[i]*2-b))
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
result=10000000000
total=0
for i in range(n-1):
    total +=a[i]
    if abs(sum(a)-2*total)<result:
        result=abs(sum(a)-2*total)
print(result)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
result=10000000000
total=0
suma=sum(a)
for i in range(n-1):
    total +=a[i]
    sa = abs(suma - 2*total)
    if sa <result:
        result=sa
print(result)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
    suma = 0
    for j in range(i+1):
        suma+=a[j]
    kari = abs(SUM-2*suma)
    MIN = min(MIN,kari)
print(MIN)

# Optimized solution
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(eval(input()))
    a = list(map(int,input().split()))
    print((solve(N,a)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
ans = 2*10**9
X = sum(a)
for i in range(n-1):
    x = sum(a[:i+1])
    ans = min(ans,abs(X-x*2))
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
s = sum(a)
ans = 10**20
x = 0
for i in range(n-1):
    x += a[i]
    y = s - x
    tmp = abs(x-y)
    ans = min(ans,tmp)
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
x = 0
y = 0
min = abs(sum(a[0:1])-sum(a[1:N]))
for i in range(3,N):
    x = sum(a[0:i])
    y = sum(a[i:N])
    if abs(x-y) <= min:
        min = abs(x-y)
print(min)


# Optimized solution

N = int(eval(input()))
a = list(map(int,input().split()))
x = a[0]
y = sum(a[1:])
ans = abs(x-y)
for i in range(1,N-1):
    x += a[i]
    y -= a[i]
    ans = min(abs(x-y),ans)

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
ruisekiwa = [0]*(N+1)
now = 0
minimum = 10**10
for i in range(N):
  now += A[i]
  ruisekiwa[i+1] = now
for i in range(N-1):
  snuke = ruisekiwa[i+1]
  arai = ruisekiwa[N]-snuke
  K = abs(snuke-arai)
  if K < minimum:
    minimum = K
print(minimum)

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
r = [0]*(N+1)
#累積和
a = 0
for i in range(N):
  a += A[i]
  r[i+1] = a
minimum = 10**18
for i in range(1,N):
  snuke = r[i]
  arai = r[N]-r[i]
  if minimum > abs(snuke-arai):
    minimum = abs(snuke-arai)
print(minimum)
# Original solution
def inpl(): return input().split()

n = int(eval(input()))
a = list(map(int, inpl()))
sa = sum(a)
b = [a[0]]
for i in range(1, n - 1):
    b.append(a[i] + b[i - 1])

ans = float('inf')
for x in b:
    ans = min(ans, abs(sa - 2 * x))
print(ans)

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

ret = 10 ** 15

s = 0
t = sum(a)
a.pop()  # 最後の要素は取れない
for x in a:
    s += x
    t -= x
    ret = min(ret, abs(s - t))

print(ret)
# Original solution
# coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
X = sum(A)
ans = float("inf")
x = 0
for i in range(N):
    x += A[i]
    if i < N-1:
        ans = min(ans, abs(X - 2 * x))
print(ans)

# Optimized solution
# coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
sunuke = sum(A)
ara = 0
ans = float("inf")
for i in range(N-1, 0, -1):
    sunuke -= A[i]
    ara += A[i]
    ans = min(ans, abs(sunuke - ara))
print(ans)