Problem:
 Score : 300 points    Problem Statement 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 1 6
1 2 3 4 5 6      Sample Output 1 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.       Sample Input 2 2
10 -10      Sample Output 2 20  Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10 , y=-10 , and thus |x-y|=20 .

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

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

def rui(A):
    R=[A[0]]*len(A)
    for i in range(len(A)-1):
        R[i+1]=R[i]+A[i+1]
    return R
R=rui(A)
S=sum(A)
ans=10**20
for i in range(n-1):
    a=R[i] ; b=S-a
    ans=min(ans, abs(a-b))
print(ans)

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

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

t = A[-1]
ans = float('inf')
for i in A[0:n-1]:
    ans = min(abs(i - (t-i)), ans)

print(ans)

Solution (Python):


N = int(input())
A = list(map(int, input().split()))[::-1]

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

S = sum(A) - A[0]

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

print(ret)

Solution (Python):
N = int(input())

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

sum_a = sum(A)
ans = 10 ** 10

x = 0
for i in range(N-1):
    x += A[i]
    y = sum_a - x
    ans = min(ans, abs(x-y))
print(ans)

Solution (Python):
N, *A = map(int, open(0).read().split())

ans = 10**18
X = sum(A)
x = 0

for i,a in enumerate(A, start=1):
    if i == N: break
    x += a
    ans = min(ans, abs(X - (x * 2)))

print(ans)

Solution (Python):
from itertools import accumulate

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

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

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

v = sum(a)

x = 0
ans = 1<<60
for i in range(n-1):
    x += a[i]
    ans = min(ans,abs(v-2*x))
    
    
print(ans)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
b = [0]*N
b[0] = a[0]
for i in range(1, N):
    b[i] = a[i] + b[i-1]
ans = 10**15
for i in range(0, N-1):
    ans = min(ans, abs(b[i] - (b[N-1] - b[i])))
print(ans)

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

Solution (Python):
import sys
from itertools import accumulate
n, *lst = map(int, sys.stdin.read().split())
s = sum(lst)
res = min(abs(s - 2 * i) for i in list(accumulate(lst))[:-1])
print(res)

Solution (Python):


def LI():
    return list(map(int, input().split()))


N = int(input())
A = LI()

INF = 10 ** 10


def main():
    x, y = 0, sum(A)
    ans = INF
    for a in A[:-1]:
        x += a
        y -= a
        ans = min(ans, abs(x - y))
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
ans=float("INF")
A=int(input())
l=list(map(int,input().split()))
maximum=sum(l)
n=0
for i in range(A-1):
   n+=l[i]
   ans=min(ans,abs(maximum-n*2))
print(ans)

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

s = sum(a)

ans = 10**18

x, y = 0, 0

for i in range(n-1):
    x += a[i]
    y = s - x

    ans = min(ans, abs(y - x))

print(ans)

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

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

sum_a = sum(a)
tmp = 0
div = 10**10
for i in range(N-1):
    tmp += a[i]
    div = min(div, abs((sum_a-tmp)-tmp))
print(div)

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

sm = sum(a)
tmp = a[0]*2
ans = abs(sm-a[0]*2)
for i in range(1,n-1):
    tmp += a[i]*2
    ans = min(abs(sm-tmp),ans)
print(ans)

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
sunuke = 0
arai = 0
min1 = 10**10
sum1 = sum(L)
for i in range(n-1):
    sunuke += L[i]
    arai = (sum1 - sunuke)
    min1 = min(min1,abs(sunuke-arai))
    
print(min1)

Solution (Python):
N = int(input())
numbers = list(input().split())
sum_numbers = [0] * N
sum_numbers[0] = int(numbers[0])

for i in range(N - 1):
    sum_numbers[i + 1] = sum_numbers[i] + int(numbers[i + 1])

Ans = abs(2 * sum_numbers[0] - sum_numbers[N - 1])
for j in range(N - 1):
    if Ans >= abs(2 * sum_numbers[j] - sum_numbers[N - 1]):
        Ans = abs(2 * sum_numbers[j] - sum_numbers[N - 1])
    else:
        continue

print(Ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
for i in range(1, N):
    B.append(A[i]+B[i-1])
ans = 1 << 50
for i in range(0, N-1):
    tmp = abs(2*B[i]-B[N-1])
    ans = min(ans, tmp)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
P = []

S = sum(A)

snuke = 0
ans = 10 ** 12

for i in range(N - 1):
  snuke += A[i]
  dif = abs(S - (2 * snuke))
  
  if ans >= dif:
    ans = dif
    
print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    S = sum(A)
    a = A[0]
    ans = abs(S - 2 * a)
    for i in range(1,N - 1):
        a += A[i]
        ans = min(ans,abs(S - 2 * a))
    print(ans)
    return

if __name__ == "__main__":
    main()

Solution (Python):

import numpy as np
N = int(input())
A = list(map(int,input().split()))
a = np.cumsum(A)[:-1]
b = np.cumsum(A[::-1])[:-1][::-1]
print (np.min(np.abs(a-b)))

Solution (Python):

from itertools import accumulate


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


if __name__ == "__main__":
    main()

Solution (Python):
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()
sumA = sum(A)

ans = 10**16
sunuke = 0
for a in A[:-1]:
    sunuke += a
    araiguma = sumA - sunuke
    if ans > abs(sunuke - araiguma):
        ans = abs(sunuke - araiguma)

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
d = A[0] - sum(A[1:])
c = abs(d)
for i in range(1, n-2):
  d += 2*A[i]
  c = min(c, abs(d))
    
print(c)

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

sn = sum(a)
m = a[0]
mn = abs((sn - m)-m)
for i in range(1,n):
    if(abs((sn-m)-m)<mn):
        mn =abs( (sn  - m)-m)
    
    m += a[i]
    
print(mn)

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

Solution (Python):
from itertools import accumulate
from bisect import bisect
N = int(input())

A = tuple(accumulate(map(int,input().split())))
print(min(abs(A[-1] - 2 * a) for a in A[:-1]))

Solution (Python):
import sys

n = int(input())
a = []
b = input().split(" ")
for i in range(n):
	a.append(int(b[i]))

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

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

print(mn)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
S = [0]*N
S[0] = A[0]

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

ans = float("inf")
for i in range(N-1):
    snuke = S[i]
    arai = S[N-1]-S[i]
    tmp = abs(arai - snuke)
    ans = min(ans,tmp)
print(ans)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    ta = 10 ** 20
    ts = sum(a)
    for i in range(n-1):
        t += a[i]
        ta = min(ta, abs(t - (ts - t)))
    print(ta)


if __name__ == '__main__':
    slove()

Solution (Python):
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    s = sum(a)
    t = 0
    ma = 10 ** 15
    for i in range(n-1):
        t += a[i]
        ma = min(ma, abs(t - (s - t)))
    print(ma)


if __name__ == '__main__':
    slove()

Solution (Python):
from numpy import cumsum

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

cum = list(cumsum(L))

ans = 10 ** 10
for c in range(N-1):
    l = cum[c]
    r = cum[-1] - l
    ans = min(ans, abs(r - l))

print(ans)

Solution (Python):
n = int(input())
a = tuple(map(int, input().split()))
s = sum(a)
t = 0
m = 10 ** 20
for i, v in enumerate(a):
    if i < n-1:
        t += v
        m = min(m, abs(t * 2 - s))
print(m)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
s = sum(a)
ans = float("inf")
for i in range(1, n):
    ans = min(ans, abs(s - a_t[i] * 2))
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
left = sum(a)
light = 0
ans = 10 **10

for i in range(0, N-1):
    left -= a[i]
    light += a[i]
    tmp = abs(left-light)
    if tmp < ans:
        ans = tmp

print(ans)

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

cum_sum = [0 for i in range(N)]
cum_sum[0] = a[0]
for i in range(1, N):
    cum_sum[i] = a[i] + cum_sum[i - 1]
    
ans = 2000000000000000
for i in range(0, N - 1):
    ans = min(ans, abs(cum_sum[i] - (cum_sum[N - 1] - cum_sum[i])))
    
print(ans)

Solution (Python):


import sys
import math

n=int(input())

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

total=0
for i in range(0,n):
	total+=hoge[i]
x=hoge[0]
y=total-x

res=abs(x-y)



for i in range(1,n-1):
	x+=hoge[i]
	y-=hoge[i]
	if(abs(x-y)<res):
		res=abs(x-y)
print(res)

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

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
suma = sum(a)

d = 10**15
s = 0
for aa in a[:-1] :
    s += aa
    d = min(d, abs(suma-2*s))
print(d)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
tmp = A[0]
mn = abs(sum_A - tmp*2)
for i in range(1,N-1):
    tmp += A[i]
    
    if abs(sum_A-tmp*2) < mn:
        mn = abs(sum_A-tmp*2)
print(mn)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from itertools import accumulate
sa=sum(a)
a=list(accumulate(a))
a=min([abs(2*i-sa) for i in a][:-1])
print(a)

Solution (Python):
N=int(input())
A=list(map(int,input().strip().split(' ')))
temp=0
pre=[]
for i in range(len(A)):
    temp+=A[i]
    pre+=[temp]

total=pre[-1]
MAX=10**20
for i in range(len(A)-1):
    MAX=min(MAX,abs(total-2*pre[i]))
print(MAX)

Solution (Python):
n=int(input())
num=list(map(int,input().split()))
s=sum(num)
a=num[0]
check=s-2*a
ans=abs(check)
for i in range(1,n-1):
  check-=2*num[i]
  if abs(check)<ans:
    ans=abs(check)
print(ans)

Solution (Python):
from itertools import accumulate


def main():
    n = int(input())
    lst = tuple(accumulate(map(int, input().rstrip().split())))
    total = lst[-1]
    ans = min(abs(total - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate


def main():
    n = int(input())
    lst = tuple(accumulate(map(int, input().rstrip().split())))
    ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    n = int(input())
    lst = tuple(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
*A, = map(int, input().split())
total = sum(A)
snuke = 0
ans = 10**18
for i in range(N-1):
    snuke += A[i]
    arai = total - snuke
    ans = min(ans, abs(arai - snuke))
print(ans)

Solution (Python):
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 2**((self.n-1).bit_length())
        self.op = op 
        self.e = e 
        self.v = [None]*(2*self.N-1)
        
        
        for i in range(self.N):
            self.v[i + self.N - 1] = lst[i] if i < self.n else self.e
        for i in range(self.N - 2, -1, -1):
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
        
    
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i+2])
    
    
    def query(self, l, r):
        assert l < r
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e
        R = self.e
        while left < right:
            if left % 2 == 0: 
                L = self.op(L, self.v[left])
                left += 1
            if right % 2 == 0: 
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1
            left >>= 1
            right >>= 1
        return self.op(L, R)

N = int(input())
*A, = map(int, input().split())
total = sum(A)
st = SegmentTree(A, lambda x,y:x+y, 0)
ans = 10**18
for i in range(N-1):
    snuke = st.query(0, i+1)
    arai = total - snuke
    ans = min(ans, abs(arai - snuke))
print(ans)

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

al, ar = [A[0]], [A[-1]]
for n in range(1, N - 1):
	al += [al[-1] + A[n]]
	ar += [ar[-1] + A[-(n + 1)]]
ar = ar[::-1]

ad = []
for n in range(N - 1):
	ad += [abs(al[n] - ar[n])]




print(min(ad))

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

al, ar = [A[0]], [A[-1]]
for n in range(1, N):
	al += [al[-1] + A[n]]
	ar += [ar[-1] + A[-(n + 1)]]
ar = ar[::-1]

ad = []
for n in range(N - 1):
	ad += [abs(al[n] - ar[n + 1])]




print(min(ad))

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
sum_ = sum(As)
ave = float(sum_)/2
diffs = [float('inf')]*(N-1)

mysum = 0
for i in range(N-1):
    mysum += As[i]
    diffs[i] = abs(ave-mysum)

print(int(2*min(diffs)))

Solution (Python):
import numpy

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

S = sum(a)
cs = numpy.cumsum(a)
res = abs(S - 2*cs)

print(min(res[:-1]))

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

S = sum(a)
_min  = 10000000000000000000
x = 0
for i in range(0,N-1):
  x += a[i]
  tmp = abs(S - 2*x)
  if tmp < _min:
    _min = tmp

print(_min)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
s = []

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

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

Solution (Python):
N = int(input())
lia=[int(it) for it in input().split()]
lib=[0]*(N-1)
allsum = sum(lia)
s=0
for i in range(N-1):
  s+=lia[i]
  lib[i]= abs((allsum-s)-s)
print(min(lib))

Solution (Python):
from itertools import accumulate
inf = float('inf')

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

ans = inf

for i in range(N-1):
    res = abs(A[i] - (A[-1] - A[i]))
    if res < ans:
        ans = res

print(ans)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))

for i in range(1, len(As)):
    As[i] += As[i-1]

res = 2*10**14
for i in range(len(As)-1):
    res = min(res, abs(2 * As[i] - As[-1]))
print(res)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split(' ')))
X,Y=A[0],sum(A)-A[0]
ans=abs(X-Y)
for i in range(N-2):
  X+=A[i+1]
  Y-=A[i+1]
  if abs(X-Y)<ans:
    ans=abs(X-Y)
print(ans)

Solution (Python):
n=int(input());a=list(map(int,input().split()));b=[0]
for i in a:b.append(b[-1]+i)
b=b[1:];s=b[-1];mi=abs(b[0]-(b[-1]-b[0]))
for i in range(n-1):mi=min(abs(b[i]-(b[-1]-b[i])),mi)
print(mi)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]

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

Min = 10**20
for i in range(1,N):
  Min = min(Min,abs((S[i]-S[0])-(S[N]-S[i])))
print(Min)

Solution (Python):
N = int(input())
S = 0
s_list = []

input_list = list(map(int, input().split()))
allS = sum(input_list)

for n in input_list[:-1]:
  S += n
  s_list.append(abs(allS - 2 * S))
  
print(min(s_list))

Solution (Python):
from numpy import*;n,*a=map(int,open(0).read().split());print(min(abs(cumsum(a[::-1])[::-1]-cumsum([0]+a[:-1]))[1:]))

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

res=[0 for i in range(n-1)]

for i in range(0,n-1):
    res[i] = abs(2*sums[i]-sums[-1])
        
print(min(res))

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

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


ans = 10**15
for i in range(1,n):
    k = abs(sums[i]-(sum-sums[i]))
    ans = min(k,ans)

print(ans)

Solution (Python):

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

S=[0]
s = 0
for i in range(N):
    s+=a[i]
    S.append(s)
ans=10**28
for i in range(1,N):
    ans=min(abs(S[N]-2*S[i]),ans)
print(ans)

Solution (Python):

n=int(raw_input())
s=raw_input().split(' ')

ar=[]
k=0
for i in range(len(s)):
	ar.append(int(s[i]))
	k+=int(s[i])

l=0
mn=10000000000
for i in range(len(ar)-1):
	l=l+(ar[i])
	v=(k-l)
	g=0
	if v>l:
		g=v-l
	else:
		g=l-v;
	if g<mn:
		mn=g

print(mn)

Solution (Python):
a = int(input())
x = list(map(int, input().split()))
s = sum(x)
inf = float('INF')
m = inf
S=0
for i in range(a-1):
    s-=x[i]
    S+=x[i]
    m = min(m,abs(s-S))

print(m)

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

x = 0
y = sum(a)
ans = []

for i in range(n-1):
    x += a[i]
    y -= a[i]
    ans.append(abs(x-y))

print(min(ans))

Solution (Python):
import numpy
N = input()
a = map(int, raw_input().split())
cumsum_a = numpy.cumsum(a)

cand = float('inf')
for i in range(N - 1):
  cand = min(cand, abs(cumsum_a[-1] - 2 * cumsum_a[i]))
print cand

Solution (Python):


"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""



def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    sumFormer = A[0]
    sumLatter = sum(A[1:])
    diff = abs(sumFormer-sumLatter)
    dmp(diff,'init')
    for i in range(1, N-1):
        sumFormer += A[i]
        sumLatter -= A[i]
        diff = min(diff, abs(sumFormer-sumLatter))
    return diff


def probC_v1():  
    N = getInt()
    A = getIntList()
    dmp((N, A))
    diff = 10**(9+6)
    for i in range(1, N):
        diff = min(diff, abs(sum(A[:i])-sum(A[i:])))
    return diff


debug = False  
ans = probC()
print(ans)

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

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

Solution (Python):
from itertools import accumulate

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

acc = list(accumulate(card))
s = acc[-1]
ans = float('inf')
for i in range(N-1):
    t = acc[i]
    a = s-t
    ans = min(ans, abs(t-a))
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
rui = [0] * (n+1)
for i in range(n):
  rui[i+1] = rui[i] + a[i]
ans = float("inf")
for i in range(1,n):
  ans = min(ans,abs(rui[i]-(rui[n]-rui[i])))
print(ans)

Solution (Python):
n = int(input())
cards = list(map(int, input().split()))

a = 0
b = sum(cards)
min_diff = float('inf')
for i in range(n - 1):
    a += cards[i]
    b -= cards[i]
    min_diff = min(min_diff, abs(a - b))
print(min_diff)

Solution (Python):
N = int(input())
a = list(map(int, input().split(' ')))

total = sum(a)
now = a[0]
ans = abs(total - 2*now)
for i in range(1, len(a)-1):
    now += a[i]
    ans = min(abs(total - 2*now), ans)
print(ans)

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

ans = float("inf")
X = a[0]
Y = sum(a) - a[0]

for i in range(1, N):
	if abs(X - Y) < ans:
		ans = abs(X - Y)

	X += a[i]
	Y -= a[i]

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
count = a[0]
ans = abs(total - 2*count)
for i in range(1,n-1):
    count += a[i]
    if ans > abs(total - 2*count):
        ans = abs(total - 2*count)
print(ans)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
import numpy as np
ans = float('inf')
N = int(input())
a = np.cumsum(np.array(inpl()))
suma = a[-1]
a = np.delete(a, -1)
for i in a:
    ans = min(ans, abs(suma-2*i))
print(ans)

Solution (Python):
n=int(input().strip())
a=list(map(int, input().split()))
sumx=a[0]
sumy=sum(a[1:])
ans=abs(sumx-sumy)

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

Solution (Python):
import sys
import collections
import math

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

L = [0] * N

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

min_diff = 10**20
for i in range(N-1):
    s = L[i]
    a = L[N-1] - L[i]
    diff = abs(a-s)
    min_diff = min(min_diff, diff)

print(min_diff)

sys.exit(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
t=sum(a)
c=a[0]
p=abs(t-2*a[0])
for i in range(1,n-1):
    c+=a[i]
    p=min(p,abs(t-2*c))
print(p)

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

Solution (Python):
N = int(input())
s = [0]
for a in map(int, input().split()):
    s.append(s[-1] + a)
ans = 10 ** 15
for i in range(1, N):
    ans = min(ans, abs(s[i] - (s[-1] - s[i])))
print(ans)

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

l = A[0]
r = sum(A[1:])

ret = abs(r - l)

for a in A[1:len(A)-1]:
    l += a
    r -= a
    ret = min(ret, abs(r - l))

print(ret)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
A = reads()

psum = [0] + list(accumulate(A))
ans = min(abs(psum[k] - (psum[N] - psum[k])) for k in range(1, N))
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
dif = float('inf')
snk = 0
for i in range(n-1):
    snk += a[i]
    dif = min(abs(snk*2-s),dif)
print(dif)

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

s = sum(a)
ass = 10**18
g = 0
h = s

for i in range(n-1):
    g += a[i]
    h = h-a[i]
    ass = min(ass,abs(g-h))
print(ass)

Solution (Python):

n = int(input())
aa = [0]
s = 0
for x in input().split():
    a = int(x)
    aa.append(aa[-1]+a)
    s += a

ret = abs(2*aa[1]-s)
for i in range(1,n):
    if abs(aa[i]-(s-aa[i]))<ret:
        ret = abs(aa[i]-(s-aa[i]))

print(ret)

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

b = sum(a)

c = 0

ans = 1000000000000000

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

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

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

ans = 10**20
for i in range(n-1):
    ans = min(ans, abs(a[-1]-2*a[i]))

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from itertools import accumulate
b = list(accumulate(a))
ans = float("INF")
for i in range(n-1):
  ans = min(ans, abs(b[i]-(b[-1]-b[i])))
print(ans)

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

comulative_sum=[0*i for i in range(N+1)]
for i in range(1,N+1):
    comulative_sum[i] = comulative_sum[i-1]+A[i-1]
minimum=pow(10,18)
for i in range(1,N):
    minimum=min(abs(comulative_sum[i]-(comulative_sum[N]-comulative_sum[i])), minimum)
print(minimum)

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

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

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

print(ans)

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

Solution (Python):
N = int(input())

A = list(map(int,input().split()))
B = [] 

s = 0
for a in A:
    s += a
    B.append(s)

sabun_m = abs(B[N-1] - (B[0]*2))

'''
1 2 3 4

1 | 2 3 4 (1234-1)-1
'''

for b in B[1:N-1]:
    sabun = abs(B[N-1] - (b*2))
    if sabun < sabun_m:
        sabun_m = sabun
        
print(sabun_m)

Solution (Python):
import itertools

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

ts = list(itertools.accumulate(A))
total = ts[-1]

r = list(itertools.accumulate((abs(total - t * 2) for t in ts[:-1]), min))[-1]

print(r)

Solution (Python):
import itertools

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

ts = list(itertools.accumulate(A))
total = ts[-1]
total_half = total / 2

r = sorted(ts[:-1], key=lambda x:abs(x - total_half))[0]
print(abs(total - r - r))

Solution (Python):
from itertools import accumulate

N=int(input())
A=[int(x) for x in input().split()]
ans=abs(sum(A)-A[0]*2)

S=list(accumulate(A))

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

print(ans)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
total=sum(a)
x=0
lis=[]
for i in range(n-1):
    x+=a[i]
    lis.append(abs(2*x-total))
print(min(lis))

Solution (Python):



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

sum1 = 0
sum2 = sum(As)

min_diff = float('inf')

for a in As[0:len(As)-1]:
    sum1 += a
    sum2 -= a
    
    min_diff = min(min_diff, abs(sum1 - sum2))
print(min_diff)

Solution (Python):
n = int(input())
j = list(map(int, input().split()))
k = [j[0]]
mi = 9999999999

for i in range(1, len(j)):
    k.append(k[i - 1] + j[i])
for m in range(len(k) - 1):
    mi = min(abs(k[n - 1] - 2 * k[m]), mi)

print(mi)

Solution (Python):
n = int(input())

j = list(map(int, input().split()))
k = [j[0]]
for i in range(1, len(j)):
    k.append(k[i-1] + j[i])
mi = 9999999999
for m in range(len(k)-1):
    mi = min(abs(k[n - 1] - 2 * k[m]), mi)
print(mi)

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

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

for i in range(1, N - 1):
	x += a[i]
	y -= a[i]
	res = min(res, abs(x - y))

print(res)

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

cum_sum = [0]*N
cum_sum[0] = a[0]

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

res = 10**15
for i in range(N-1):
	x = cum_sum[i]
	y = cum_sum[N-1] - cum_sum[i]
	res = min(res, abs(x-y))

print(res)

Solution (Python):

def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)

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

x = 0
sum_ = sum(a)
sa = []
for i in range(n - 1):
    x += a[i]
    y = sum_ - x
    sa.append(abs(x - y))

print(min(sa))

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
x=a[0]
y=sum(a)-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)

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

    

    summation = []
    sumtemp = sum(a)
    tmp1 = 0
    for i in range(len(a)-1):
        tmp1 += a[i]
        tmp2 = sumtemp - tmp1
        tmp = abs(tmp1 - tmp2)
        summation.append(tmp)
        
    print(min(summation))

main()

Solution (Python):
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):
    x += A[i]
    y -= A[i]
    ans = min(ans, abs(x - y))
print(ans)

Solution (Python):
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):
    x += A[i]
    y -= A[i]
    ans = min(ans, abs(x - y))
print(ans)