Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - -10^{9} \leq a_i \leq 10^{9}
 - a_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N}

-----Output-----
Print the answer.

-----Sample Input-----
6
1 2 3 4 5 6

-----Sample Output-----
1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Difficulty: introductory

Starter code:

Solutions:
import sys
import itertools

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    B = list(itertools.accumulate(A, initial=0))
    s = 0
    ans = 10 ** 12
    for i in range(N - 1, 0, -1):
        s += A[i]
        ans = min(ans, abs(s - B[i]))

    return ans


print(solve())


import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

if N == 2:
    print((abs(A[0] - A[1])))
else:
    ans = INF

    x = A[0]
    y = sum(A[1:])

    for i in range(1, N-2):
        x = x + A[i]
        y = y - A[i]

        tmp = abs(x - y)
        if tmp < ans:
            ans = tmp
    print(ans)


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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    if i==0:
        m=abs(t)
    else:
        m=min(abs(t),m)
print(m)

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

lsum = a[0]
rsum = sum(a[1:])
ans = abs(lsum - rsum)

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

    if res < ans:
        ans = res

print(ans)

def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    x = a_lst[0]
    y = sum(a_lst) - x

    minimum = abs(x - y)
    for i in range(1, n - 1):
        a = a_lst[i]
        x += a
        y -= a
        minimum = min(minimum, abs(x - y))

    print(minimum)


def __starting_point():
    main()
__starting_point()

N = int(input())
a = [int(x) for x in input().split()]
ans = 10**9*N
front = 0
back = sum(a)
for i in range(N-1):
    front += a[i]
    back -= a[i]
    ans = min(ans, abs(front-back))
print(ans)

N = int(input())
A = [0]+list(map(int,input().split()))
for i in range(1,N+1):
  A[i] = A[i]+A[i-1]
ans = float('inf')
for i in range(1,N):
  ans = min(ans, abs(A[N]-2*A[i]))
print(ans)

import itertools
n = int(input())
a = list(map(int, input().split(" ")))
#print(a)
mini = 10 ** 10
suma = list(itertools.accumulate(a))
for i in range(0, n-1):
  #print(suma[i],(suma[-1]))
  mini = min(mini, abs(suma[-1]-suma[i]*2))
print(mini)

n = int(input())
A = list(map(int, input().split()))
r = sum(A)-A[0]
l = A[0]
ans = abs(r-l)
for i in range(1,len(A)-1):
    r -= A[i]
    l += A[i]
    ans = min(ans, abs(l-r))
print(ans)

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    if N == 2:
        print((abs(A[1] - A[0])))
        return

    t = list(accumulate(A, add))
    r = list(accumulate(reversed(A), add))

    ans = INF
    for i in range(N-2):
        ans = min(ans, abs(t[i] - r[-2-i]))

    print(ans)


def __starting_point():
    main()

__starting_point()

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

sum_a=sum(a)
ans = 10**11
x=0
for i in range(N-1):
    x += a[i]
    diff = abs(sum_a - 2 * x)
    if diff<ans:
        ans=diff


print(ans)


N = int(input())
a = list(map(int,input().split()))
s = sum(a)
su = a[0]
ar = s - su
ans = abs(su-ar)
for i in range(1,N-1):
    su += a[i]
    ar = s - su
    if ans > abs(su-ar):
        ans = abs(su-ar)
print(ans)

n = int(input())
L = list(map(int,input().split()))

li = [0]

for i in range(n):
    li.append(li[i]+ L[i])

sumL = sum(L)
#print(sumL)
ans = 10**10
for i in range(1,n):
    diff = abs(li[i] - (sumL - li[i]))
    #print(diff,li[i],sumL-li[i])
    ans = min(ans,diff)        
print(ans)

import sys
from itertools import accumulate

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


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

    res = f_inf
    R = [0] + list(accumulate(A))
    for i in range(1, n):
        s = R[i] - R[0]
        a = R[-1] - R[i]
        diff = abs(s - a)
        res = min(res, diff)
    print(res)


def __starting_point():
    resolve()

__starting_point()

n = int(input())
a = list(map(int, input().split()))
sa = sum(a) # sum a
cs = 0 # cards sunuke
arr = []

for i in range(n-1):
  cs += a[i]
  ca = sa -cs #cards araiguma
  arr.append(abs(cs-ca))
 
print(min(arr))

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

sum_A = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    sum_A[i] = sum_A[i - 1] + A[i - 1]

ans = float('inf')
for i in range(1, n):
    ans = min(abs(sum_A[i] - (sum_A[-1] - sum_A[i])), ans)
print(ans)

from itertools import accumulate

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

if n == 2:
    print(abs(A[0]-A[1]))
    return

B = list(accumulate(A))

ans = float("inf")
y = 0
for i in range(n-1, 0, -1):
    x = B[i-1]
    y += A[i]
    ans = min(ans, abs(x-y))
print(ans)

N = int(input())
a = list(map(int, input().split()))
s = sum(a)
data = [a[0]]
m = abs(s - 2 * a[0])

for i in range(1, N - 1):
    data.append(a[i] + data[i - 1])

for i in range(0, N - 1):
    if abs(s - 2 * data[i]) < m:
        m = abs(s - 2 * data[i])

print(m)



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

print(min(B))

n=int(input())
a=list(map(int,input().split()))
snuke=sum(a)
arai=0
ans=10**20
for i in range(n-1):
    snuke-=a[i]
    arai+=a[i]
    ans=min(ans,abs(snuke-arai))
print(ans)


n = int(input())
#a, b = map(int,input().split())
al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

total = sum(al)
mn = abs(total-2*al[0])
x = 0
for i in range(1, n-1):
    x += al[i-1]
    y = total-x
    mn = min(mn, abs(x-y))

print(mn)


n=int(input());a=list(map(int,input().split()));f,b,c=0,sum(a),float('inf')
for i in range(n-1):
  f,b=f+a[i],b-a[i]
  c=min(c,abs(f-b))
print(c)

n=int(input())
a=[0]+list(map(int,input().split()))
import itertools
a=list(itertools.accumulate(a))
ans=1e15
for i in range(1,n):
    ans=min(ans,abs(a[n]-2*a[i]))
print(ans)

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
  t-=2*a[i]
  if i==0:
    m=abs(t)
  else:
    m=min(abs(t),m)
print(m)

n = int(input())
a = list(map(int, input().split()))
val = 0
l = []
s = sum(a)
hlf = s/2
for i in range(n-1):
    val += a[i]
    l.append(abs(hlf - val))

val = min(l)
print((int(val*2)))


N=int(input())
a=list(map(int,input().split()))
ans=10000000000000000000
c=0
s=sum(a)
for i in range(N-1):
    c+=a[i]
    s-=a[i]
    if abs(c-s)<ans:
        ans=abs(c-s)
print(ans)


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

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

s = [0]*(n+1)
for i in range(n):
    s[i+1] += a[i] + s[i]
#print(s)
ans = float("inf")
for i in range(1, n):
    x = s[i]
    y = s[n]-s[i]
    ans = min(ans, abs(x-y))
print(ans)

n = int(input())
a = list(map(int,input().split()))
snuke = 0
arai = sum(a)
ans = 2*(10**9)
for i in range(n-1):
    snuke += a[i]
    arai -= a[i]
    ans = min(ans,abs(snuke-arai))
print(ans)

n = int(input())
a = list(map(int, input().split()))
import math
sunuke = 0
kuma = sum(a)

memo = abs(2*a[0] - sum(a))
ans = abs(2*a[0] - sum(a))

for i in range(n):
    sunuke += a[i]
    kuma -= a[i]
    if abs(sunuke-kuma) > memo:
        ans = memo
    else:
        memo = abs(sunuke-kuma)

print(ans)


# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 02:27:51 2020

@author: liang
"""

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

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

#
# 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(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)


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

#
# 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(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)


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

N = int(input())
a = list(map(int,input().split()))
ans = float("inf")
snuke = 0
arai = sum(a)
for i in range(N-1):
    snuke += a[i]
    arai -= a[i]
    ans = min(abs(snuke-arai), ans)
print(ans)

from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a = list(accumulate(a))
ans = 10**10
for i in range(n-1):
    ans = min(ans, abs(a[i]-a[-1]+a[i]))
print(ans)

from itertools import accumulate
INF = float('inf')
N = int(input())
A = [int(x) for x in input().split()]

cumA = list(accumulate(A))
ans = INF
for i in range(N - 1):
    x = cumA[i]
    y = cumA[N - 1] - cumA[i]
    ans = min(ans, abs(x - y))

print(ans)

n=int(input())
a=list(map(int,input().split()))
ans=2*(10**14)+1
s=sum(a)
x=0
y=s
for i in range(n-1):
    x+=a[i]
    y-=a[i]
    ans=min(ans,abs(x-y))
print(ans)

import numpy as np
n = int(input())
al = list(map(int, input().split()))
bl = list(np.cumsum(al))

ans = 1001001001001
for i in range(n-1):
    ans = min(ans, abs(bl[i] - (bl[-1]-bl[i])))
print(ans)

N = int(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)

n=int(input())
a=list(map(int, input().split()))
s1=sum(a)
s2=0
ans=10**18
for i in range(n - 1):
    s1-=a[i]
    s2+=a[i]
    ans=min(ans,abs(s1-s2))
print(ans)

N=int(input())
a=list(map(int,input().strip().split()))
#累積和
s_l=[]
s=0

for n in range(N):
    s+=a[n]
    s_l.append(s)

MIN=10**15
for n in range(N-1):
    MIN=min(MIN,abs(s-s_l[n]*2))

print(MIN)

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

cumsum = [0 for _ in range(n)]
cumsum[0] = a[0]

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

result = [0 for _ in range(n-1)]
last = cumsum[-1]
#print(last)
for i in range(n-1):
    result[i] = abs(last - 2 * cumsum[i])

print((min(result)))






n=int(input())
a=[int(i) for i in input().split()]

sunuke=0
araiguma=sum(a)

min_sa=100000000000000

for i in range(n-1):
    sunuke+=a[i]
    araiguma-=a[i]
    min_sa=min(min_sa,abs(araiguma-sunuke))
print(min_sa)

N = int(input())
A = [int(a) for a in input().split(" ")]

sA = []
for i in range(len(A)):
  if i == 0:
    sA.append(A[0])
  else:
    sA.append(sA[i - 1] + A[i])

s = sum(A)
dA = [abs(2 * sA[j] - s) for j in range(len(sA) - 1)]

print(min(dA))

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



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

    acc_A = []
    acc = 0
    for a in A:
        acc += a
        acc_A.append(acc)

    minv = 10e10
    for i in range(0, N-1):
        minv = min(abs(acc_A[i]-(acc_A[-1]-acc_A[i])), minv)
    print(minv)
__starting_point()

from itertools import accumulate
N = int(input())
A = tuple(accumulate(map(int, input().split())))
x = A[-1]
y = A[0]
ans = abs(x - y - y)
for a in A[:-1]:
    ans = min(ans, abs(x - a - a))
print(ans)

N = int(input())
lsa = list(map(int,input().split()))
sunu = lsa[0]
ara = sum(lsa)- lsa[0]
ans = abs(ara-sunu)
for i in range(1,N-1):
    sunu += lsa[i]
    ara -= lsa[i]
    ans = min(ans,abs(ara-sunu))
print(ans)

import sys
import numpy as np

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return list(map(int, stdin.readline().split()))
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    cumA = np.cumsum(A)
    total = cumA[-1]
    ans = 10 ** 10000
    for a in cumA[:-1]:
        ans = min(ans, abs(a - (total - a)))
    print(ans)


def __starting_point():
    main()

__starting_point()

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

s = A[0]
s_ = sum(A[1:])
gap = abs(s-s_)
for i in range(1, n-1):
    s += A[i]
    s_ -= A[i]
    if gap > abs(s-s_):
        gap = abs(s-s_)
print(gap)

#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from itertools import accumulate
    s = sum(a)
    return min(abs(s-2*aa) for aa in accumulate(a[:-1]))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print((solve(N, a)))

def test():
    import doctest
    doctest.testmod()

def __starting_point():
    #test()
    main()

__starting_point()


N=int(input())
A=list(map(int,input().split()))
total = sum(A)
arai = 0
sunuke = 0
ans = float('inf')

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

print(ans)


#!/usr/bin/env python

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

l = a[0]
r = sum(a)-l
ans = abs(l-r)

for i in range(1, n-1):
    l += a[i]
    r -= a[i]
    if abs(l-r) <= ans:
        ans = abs(l-r)

print(ans)


#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-10-10 15:17:07 +0900
# LastModified: 2020-10-10 15:25:36 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from itertools import accumulate


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_ac = list(accumulate(A))
    ans = A_ac[-1]
    for i, ac in enumerate(A_ac):
        if i == 0:
            ans = abs(2*ac-A_ac[-1])
        if i == N-1:
            break
        if abs(2*ac-A_ac[-1]) < ans:
            ans = abs(2*ac-A_ac[-1])
    print(ans)



def __starting_point():
    main()

__starting_point()

# C - Splitting Pile
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = sum(a)
    cnt = 0
    ans = float('inf')

    for i in range(n-1):
        cnt += a[i]
        ans = min(ans, abs(a_sum-cnt*2))
    else:
        print(ans)


if __name__ ==  "__main__":
    main()

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

if n == 2:
    print(abs(A[0]-A[1]))
    return

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

ans = 10**9+1
for x in cum_sum[1:-1]:
    y = cum_sum[-1] - x
    ans = min(ans, abs(x-y))
print(ans)

n = int(input())
a = [int(x) for x in input().split()]
s = [0] * (n+2)
for i in range(n):
  s[i+1] = s[i] + a[i]

res = 10 ** 10

for i in range(1,n):
  res = min(res,abs(s[i] - (s[n] - s[i])))

print(res)

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

s = sum(a)
t = 0
minimum = math.inf
for i in range(N-1):
    t += a[i]
    s -= a[i]
    minimum = min(minimum,abs(s-t))
print(minimum)

a = int(input())
b = [int(s) for s in input().split()]
su = sum(b) - b[a-1]
ar = b[a-1]
ans = abs(su - ar)

for i in range(2, a-1):
  su = su - b[a-i]
  ar = ar + b[a-i]
  tmp = abs(su - ar)
  if tmp < ans:
    ans = tmp
  tmp = 0

print(ans)


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

sunuke = [0] * (N)
guma = [0] * (N)

for i in range(N-1):
  if i == 0:
    sunuke[i] += A[i]
    continue  
  sunuke[i] += sunuke[i-1] + A[i]

for j in range(N-1,0,-1):
  if j == N - 1:
    guma[j] += A[j]
    continue
  guma[j] += guma[j+1] + A[j]
  
ans = float("inf")
for k in range(N-1):
  ans = min(ans, abs(sunuke[k] - guma[k+1]))

print(ans)

with open(0) as f:
    N, *a = list(map(int, f.read().split()))
score = -sum(a[1:]) + a[0]
ans = abs(score)
for x in a[1:N-1]:
    score += 2*x
    ans = min(ans, abs(score))
print(ans)


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

n = int(input())
main = list(map(int, input().split()))

total = sum(main)
beg = 0
final = float('inf')
for i in range(len(main) - 1):
    beg += main[i]
    total -= main[i]
    final = min(final, abs(beg - total))

print(final)


n=int(input())
a=list(map(int,input().split()))
ans=float("inf")
x=0
b=sum(a)
for i in range(n):
    x+=a[i]
    if i+1<n:
        ans=min(ans,abs(b-2*x))    
print(ans)

N=int(input())
a=list(map(int,input().split()))
l,r=a.pop(0),sum(a)
ans=10**10
for i in a:
    ans=min(ans,abs(l-r))
    l,r=l+i,r-i
print(ans)

N = int(input())
A = list(map(int,input().split()))
S1 = A[0]
S2 = sum(A)-A[0]
B = [abs(S1-S2)]

for i in range(N-2):
  S1 += A[i+1]
  S2 -= A[i+1]
  B.append(abs(S1-S2))

print(min(B))

N=int(input())
*A,=map(int,input().split())
t=sum(A)

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

import numpy as np
N = int(input())
a = list(map(int, input().split()))

a = np.array(a)
cum = np.cumsum(a)[:-1]
rcum = np.cumsum(a[::-1])[:-1]
ans = abs(cum - rcum[::-1])

print((np.min(ans)))


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

s = sum(a)

x = a[0]
ans = abs(x - (s - x))
for i in a[1:-1]:
  ans = min(ans, abs(x - (s - x)))
  x += i
print(ans)

n=int(input())
A=list(map(int,input().split()))
S=sum(A)
x=A[0]
y=S-x
xy_min=abs(x-y)
for i in range(1,n-1):
  x+=A[i]
  y=S-x
  xy=abs(x-y)
  if xy<xy_min:
    xy_min=xy
print(xy_min)

from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
AA = list(accumulate([0] + A))
ans = 10 ** 20
for i in range(1, n):
    temp1 = AA[i]
    temp2 = AA[-1] - temp1
    delta = abs(temp1 - temp2)
    ans = min(delta, ans)
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = []

s = sum(a)
cnt = 0
for i in range(n - 1):
    cnt += a[i]
    rem = s - cnt
    l.append(abs(cnt - rem))
    
print(min(l))

n=int(input()) 
c=list(map(int, input().split()))
s = sum(c)
l = []
x = 0
y = s

for i in c[:n-1]:
    x += i
    y -= i
    l += [abs(x-y)]
print(min(l))

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    n = i_input()
    a = i_list()

    total = sum(a)

    ans = INF
    trial = 0
    for i in a[:-1]:
        trial += i
        left = total - trial
        ans = min(ans,abs(trial-left))
    print(ans)


def __starting_point():
    main()

__starting_point()

n = int(input())
a = list(map(int,input().split()))
nums = []
total = 0
for num in a:
    total += num
    nums.append(total)
minVal = 10 ** 9 * 2 + 1
for i in range(n - 1):
    sub = total - nums[i]
    minVal = min(abs(sub - nums[i]), minVal)
print(minVal)

N=int(input())
a=list(map(int,input().split()))
sum=[0]
for i in range(0,N):
    sum.append(sum[-1]+a[i])
ans=abs(sum[N]-2*sum[1])
for i in range(1,N):
    ans=min(ans,abs(sum[N]-2*sum[i]))
print(ans)


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

# C - Splitting Pile
N = int(input())
A = list(map(int,input().split()))

s = [0]*(N+1)
for i in range(N-1):
    s[i+1] = s[i] + A[i]

ans = 10**10
for i in range(1,N):
    diff = abs((s[N-1] + A[-1] - s[i]) - s[i])
    ans = min(ans,diff)
print(ans)

n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
res = 10 ** 10
tmp_sum = 0
for i in range(n - 1):
    tmp_sum += a[i]
    res = min(res, abs(tmp_sum - (sum_a - tmp_sum)))

print(res)


with open(0) as f:
    N, *a = map(int, f.read().split())
score = -sum(a[1:]) + a[0]
ans = abs(score)
for x in a[1:N-1]:
    score += 2*x
    ans = min(ans, abs(score))
print(ans)

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

s = A[0]
a = sum(A[1:])

ans = abs(s - a)

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

print(ans)

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

rui=[]
rui.append(a[0])
for x in range(1,n):
  b=rui[-1]+a[x]
  rui.append(b)

ans=[]
for y in range(n-1):
  ans.append(abs((rui[n-1]-rui[y])-rui[y]))
  
print(min(ans))

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
left = 0
right = sum(A)
MIN = float('inf')
for i in range(n-1):
    left += A[i]
    right -= A[i]
    #print(left, right)
    MIN = min(MIN,abs(left - right))
print(MIN)


import itertools
n = int(input())
a = list(map(int, input().split()))

n_acc = itertools.accumulate(a)
#r_acc = itertools.accumulate(a[::-1])
# 1, 3, 6, 10, 15 ,21
# 1 vs 20
# 3 vs
#print(n_acc, r_acc)


sigma = sum(a)
ans = 10 ** 16

for i, val in enumerate(n_acc):
    if (i == len(a) - 1):
        break

    rest = sigma - val
    ans = min(abs(val - rest), ans)


print(ans)











#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline
INF = pow(10,10)
# @njit
def solve(n,a):
  res = INF
  x = 0
  y = sum(a)
  for i in range(n-1):
    x += a[i]
    y -= a[i]
    res = min(res,abs(x-y))
  return res



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print((solve(N,a)))
  return

def __starting_point():
  main()

__starting_point()

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

s = sum(a)
x = 0
ans = abs(2 * a[0] - s)
snuke = a[0]

for i in range(1, n-1):
    snuke += a[i]
    if abs(2 * snuke - s) < ans:
        ans = abs(2 * snuke - s)

print(ans)


n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
s=sum(a)
t=0
for i in range(n-1):
    b.append(t+a[i])
    t=b[i]
for i in range(n-1):
    c.append(abs(2*b[i]-s))
c.sort()
print(c[0])

n = int(input())
a = list(map(int,input().split()))
s = sum(a)
temp,ans = 0,float('inf')
for v in a[:-1]:
  temp += v
  s -= v
  ans = min(ans,abs(temp-s))
print(ans)

n = int(input())
al = list(map(int, input().split()))
bl = [0]*(n+1)
cl = [0]*(n-1)

for i in range(n):
    bl[i+1] = al[i] + bl[i]

for j in range(1, n):
    cl[j-1] = abs(bl[j] - (bl[n] - bl[j]))

print(min(cl))

n=int(input())
a=list(map(int,input().split()))
sm=sum(a)
s=a.pop(0)
mn=abs(sm-s*2)
for i in a[:-1]:
  s+=i
  mn=min(mn,abs(sm-s*2))
  
print(mn)

n = int(input())
a = list(map(int,input().split()))
asum = [0]*(n+1)

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

ans = 10**12
for i in range(1,n):
    snu = asum[i]
    arai = asum[-1] - asum[i]
    ans_ = abs(snu - arai)
    if ans >ans_:
        ans = ans_
        
print(ans)

n = int(input())
arr = list(map(int, input().split()))
sum1 = 0
sum2 = sum(arr)
min_ = 1<<60

for i in range(n-1):
    sum1 += arr[i]
    sum2 -= arr[i]
    min_ = min(min_, abs(sum1 - sum2))
print(min_)

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

s = a[0]
t = sum(a) - a[0]

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


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

cum=[0]
for i in range(N):
  cum.append(cum[-1]+a[i])
  
ans=10**20
for i in range(1,N):
  tmp = abs(cum[-1]-cum[i]-cum[i])
  ans = min(ans, tmp)
  
print(ans)

n = int(input())
a = list(map(int,input().split()))
li = [a[0]]
for i in range(n-1):
    li.append(li[i]+a[i+1])

b = []
for i in range(n-1):
    b.append(abs(li[-1]-li[i]*2))
print(min(b))

n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])
s=sum(a)
ans=10**20
for i in range(n-1):
    ans=min(ans,abs(s-2*b[i]))
print(ans)


N=int(input())
L=list(map(int,input().split()))
sums=0
a=sum(L)
mina=10**10
for i in range(N-1):
  a-=2*L[i]
  mina=min(mina,abs(a))
print(mina)

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

sa = [0 for i in range(n)]
sc = sum(a)
c = 0
for i in range(n):
  c += a[i]
  sa[i] = c
ans = 10**10

for i in range(1,n):
  x = sc-sa[i-1]
  v = abs(x-sa[i-1])
  ans = min(ans,v)
print (ans)


N = int(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):
    a = A[i]
    x += a
    y -= a
    dif = abs(x - y)
    if dif < ans:
        ans = dif
print(ans)

n=int(input())
a=[int(x) for x in input().rstrip().split()]

ruiseki=[0]
for i in range(n):
  ruiseki.append(ruiseki[i]+a[i])

ans=float('inf')
last=ruiseki[len(ruiseki)-1]
# print(last)
# print(ruiseki)
for i in range(1,len(ruiseki)-1):
  now=(last-ruiseki[i])
  ans=min(ans,abs(ruiseki[i]-now))
print(ans)
  




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

S = sum(A)

snk = 0
arigm = S

ans = 1e20

for i in range(N-1):
  snk += A[i]
  arigm -= A[i]
  #print(snk,arigm)
  ans = min(abs(snk-arigm),ans)
print(ans)