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 = list(map(int, input().split())) 
x_list = [0 for i in range(n-1)]
a = 0
for i in range(n-1):
	a += a_list[i]
	x_list[i] = a
total = sum(a_list)
r = abs(total - x_list[0]*2)
for x in x_list:
	r = min(r, abs(total - x*2))
print(r)

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0

if n == 2:
    print(abs(L[1]-L[0]))
    exit ()
ans = 10**20
for i in range(n-1):
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    ans = min(ans,sa)
print(ans)

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

if n==2:
    print(abs(a[1]-a[0]))
else:
    asum=sum(a)
    xsum=0
    xmin=n*(10**9)+1
    for i in range(n-1):
        xsum=xsum+a[i]
        xmin=min(xmin,abs(asum-2*xsum))
    print(xmin)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
s = [0] * (N + 1)
for i in range(N):
    s[i + 1] = s[i] + a[i]
ans = float('Inf')
for i in range(1, N):
    
    kouho = abs(s[i] - ((s[-1]) - s[i]))
    if ans > kouho:
        ans = kouho
    
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
s_right = [0] * (N + 1)
s_left = [0] * (N + 1)
for i in range(N):
    s_left[i + 1] = s_left[i] + a[i]
    s_right[i + 1] = s_right[i] + a[N - 1 - i]
ans = float('Inf')
for i in range(1, N):
    
    if ans > abs(s_left[i] - s_right[N - i]):
        ans = abs(s_left[i] - s_right[N - i])
print(ans)

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

sumA = sum(a)
x_y = []
x = 0

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

print(min(x_y))

Solution (Python):




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

    A_sum = sum(A)
    tmp = 0

    result = []

    for a in A:
        tmp += a
        result.append(abs(A_sum - tmp * 2))
    print(min(result[:-1]))


if __name__ == "__main__":
    main()

Solution (Python):
def resolve():

    from itertools import accumulate

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

    B = [0] + A
    B = list(accumulate(B))  

    minans=10**10
    
    for i in range(1, N):
        snuke=B[i]
        arai=B[-1]-B[i]
        minans = min(minans,abs(snuke-arai))
    print(minans)


resolve()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=10**20
sumA=sum(A)
x=0
for i in range(n-1):
  x+=A[i]
  ans=min(ans,abs(sumA-x*2))

print(ans)

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

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

c=x-y
ans=abs(c)

for i in range(1,N-1):
  c+=2*A[i]
  if abs(c)< abs(ans):
    ans = abs(c)

print(ans)

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
from itertools import accumulate
acc = list(accumulate(As))
s = sum(As)
mn = 10**10
for i,x in enumerate(acc[:-1]):
    y = s - x
    if mn >= abs(x-y):
        mn = abs(x-y)
print(mn)

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

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    cards = [int(item) for item in input().split()]

    all_sum = sum(cards)

    
    def candi_abs(sumu):
        
        return abs(2*sumu - all_sum)

    res = 3 * 10**9
    sumu = 0
    for i in range(N-1):
        sumu += cards[i] 
        res = min(res, candi_abs(sumu))

    print(res)


if __name__ == "__main__":
    resolve()

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

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

ans = 10 ** 20

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

    print(ans)

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

accum=[0]
for i in range(N):
    accum.append(accum[i]+a[i])

accum.remove(0)

S=accum[-1]
lst=[]
for i in range(N-1):
    lst.append(abs(S-accum[i]*2))
print(min(lst))

Solution (Python):
import numpy
N = int(input())
List = list(map(int,input().split()))
cumsum = numpy.cumsum(List)
total = sum(List)
result = [abs(total -item*2) for item in cumsum ]
print(min(result[:-1]))

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


for i in range(n):
    d[i] = abs(2*d[i]-s)

d.pop(n-1)
print(min(d))

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

Solution (Python):
S=[]
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);x=10**10;p=0
S.append(A[0])
for i in range(1,N):
  S.append(S[i-1]+A[i])

C[0]=abs(A[0]-(S[-1]-S[0]))
for i in range(1,N-1):
  C[i]=abs(S[i-1]+A[i]-(S[-1]-S[i]))
  if x>(C[i]):
    x=(C[i])
    p=i
print(abs(S[p-1]+A[p]-(S[-1]-S[p])))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
s=[0]*(N+1)
for i in range(N): s[i + 1]=s[i]+A[i]
C=[0]*(N)
C[0]=-s[N]
x=10**10
p=0
for i in range(1, N):
    C[i]=C[i-1]+2*A[i-1]
    if x>abs(C[i]):
        x=abs(C[i])
        p=i
print(x)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = [0] * (n + 1)

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

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

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

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

B=[0]*N
B[0] = A[0]
saitei = float("inf")
for i in range(N-1):
    saitei = min(abs(B[i]-(a-B[i])), saitei)
    B[i+1] += (A[i+1] + B[i])
    
print(saitei)

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

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

su = 0
ar = sum(a)
minsc = 10**18

for i in range(n-1):
    su += a[i]
    ar -= a[i]
    minsc = min(minsc, abs(su - ar))

print(minsc)

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

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

goukei=sum(t)

ans = 10000000000000

fir = 0

for i in range(n-1):
    fir += t[i]
    sec = goukei-fir
    ans = min(ans,abs(sec-fir))
print(ans)

Solution (Python):
_,*a=map(int,open(0).read().split());s,t=sum(a),0;l=[]
for i in a:t+=i;l+=[abs(s-t*2)]
print(min(l[:-1]))

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

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

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

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

    y = sum(A)
    x = 0
    mn = float('inf')
    for i in range(N-1):
        x += A[i]
        y -= A[i]
        mn = min(mn, abs(x-y))
    
    print(mn)

if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np
from sys import maxsize

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

cumsum = np.cumsum(a)
res = maxsize
for i in range(n-1):
    val = abs(cumsum[i] - (cumsum[-1] - cumsum[i]))
    if val < res:
        res = val

print(res)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
all=sum(a)
su=0
mi=float("inf")
for i in range(N-1):
 su=su+a[i]
 if abs(all-2*su)<mi:
  mi=abs(all-2*su)
print(mi)

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

x = 0
y = total
B = []
for i in range(n-1):
    x += A[i]
    y -= A[i]
    B.append(abs(x - y))
print(min(B))

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

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


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
x=0
k=sum(a)
m = 2*10**9

for i in range(n-1):
  x+=a[i]
  if m>abs(2*x-k):
    m=abs(2*x-k)
print(m)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

ans = 2*(10**9)
S = sum(A)

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

print(ans)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
M=[float("inf")]*(N+10)
M[0]=0
for i in range(1,N+1):
	M[i]=M[i-1]+L[i-1]
ans=float("inf")
for i in range(1,N):
	X=M[i]
	Y=M[N]-M[i]
	ans=min(ans,abs(X-Y))
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()

arr=limii()
sumarr=sum(arr)
xsum=0
ans=10**1000
for i in range(n-1):
    xsum+=arr[i]
    ans=min(ans,abs(xsum-(sumarr-xsum)))
print(ans)

Solution (Python):



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


min_cost = 10**15
arai_score = sum(a_list)
snuke_score = 0


for i in range(len(a_list)-1):
    a = a_list[i]
    snuke_score += a
    arai_score = arai_score - a
    min_cost = min(min_cost, abs(snuke_score - arai_score))


print(min_cost)

Solution (Python):
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

import numpy as np
a = list(np.cumsum(a))

ans = 100000000000000000

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

print(ans)

Solution (Python):
import numpy

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

ans = 10**10
for i in range(n-1):
    ans = min(ans, abs(res[i]-(res[-1]-res[i])))
print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    sumA = [0] * (N + 1)
    for i, a in enumerate(A): sumA[i+1] = sumA[i] + A[i]
    Ans = 100000000000000000
    for i in range(N - 1):
        Ans = min(Ans, abs(sumA[i + 1] - (sumA[N] - sumA[i + 1])))
    print(Ans)


    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ruiseki = [0]*(N+1)
total = 0
now = 10**20
sa = 0
now_2 = 0
for i in range(N):
  total += A[i]
  ruiseki[i+1] = total
for i in range(1,len(ruiseki)-1):
  snuke = ruiseki[i]-ruiseki[0]
  arai = ruiseki[N]-ruiseki[i]
  now_2 = abs(snuke-arai)
  now = min(now,now_2)
print(now)

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

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

Solution (Python):
from itertools import accumulate
n=int(input())
a=list(map(int,input().split()))
s=sum(a)

acc=accumulate(a)
acc=list(acc)

sunuke=0
arai=0
ans=10**18
for i in range(1,n):
    sunuke=acc[i-1]
    arai=s-sunuke
    t=abs(sunuke-arai)
    ans=min(t,ans)
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
s = sum(a)
arr = [0 for _ in range(n)]
arr[0] = a[0]
ans = [inf for _ in range(n)]
ans[0] = abs(a[0] - (s - a[0]))
for i in range(1, n - 1):
    arr[i] = arr[i - 1] + a[i]
    ans[i] = abs(arr[i] - (s - arr[i]))
print(min(ans))

Solution (Python):

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

sunuke = 0
kuma = sum(a)
ans = pow(10, 100)
for i in range(n - 1):
    sunuke += a[i]
    kuma -= a[i]
    
    if abs(kuma - sunuke) < ans:
        ans = abs(kuma - sunuke)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
T = 0
S = sum(A)

ans = 10**18
for a in A[:-1]:
    T += a
    S -= a
    ans = min(ans, abs(T - S))

print(ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    ans = 10**18
    for i in range(1, N):
        snuke = S[i] - S[0]
        arai = S[N] - S[i]
        cur = abs(snuke - arai)
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ruiseki = [0] * (n + 1)

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

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

Solution (Python):

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

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

ans=10**19
SUM=sum(A)
for s in CS:
    ans=min(ans,abs(SUM-s-s))
print(ans)

Solution (Python):
n = input()

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

max_sum = sum(A)

a,b = A[0],sum(A[1:])
m = abs(a - b)

for i in range(1,len(A)-1):
  
  a = a+A[i]
  b = b-A[i]
  f= abs(a- b)
  if f< m:
    m = f
print(m)

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

total = sum(l)

from itertools import accumulate
x = list(accumulate(l))

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

print(min(y))

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

total = sum(a)
ans = 1000000000000007
x = 0
for i in range(n):
  x += a[i]
  if i + 1 < n:
    ans = min(ans, abs(total - 2 * x))

print(ans)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)

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

s = sum(A)
x = 0
dmin = 10**15
for a in A[:-1]:
  x += a
  dmin = min(abs(s-x-x), dmin)

print(dmin)

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

s=A[0]
S=sum(A)
ans=abs(sum(A) - 2*s)
for i in range(1,n-1):
	s += A[i]
	ans = min(ans, abs(S - 2*s))

if n > 3:
	print(ans)
else:
	print(abs(A[1]-A[0]))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
b[0] = a[0]
for i in range(1, n):
    b[i] = a[i] + b[i - 1]
c = 10 ** 15
for i in range(n - 1):
    if abs(b[n - 1] - 2 * b[i]) < c:
        c = abs(b[n - 1] - 2 * b[i])
print(c)

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

cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + a[i]

s = sum(a)
ans = 10 ** 18
for i in range(n-1):
    ans = min(ans, abs(s - 2*cum[i+1]))
print(ans)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

goukei = sum(a)
if n == 2:
    print(abs(a[0]-a[1]))
else:
    x = [0] * n
    x[0] = a[0]
    
    ans = 10 ** 11
    for i in range(1,n-1):
        x[i] = x[i-1] + a[i]
        y = goukei - x[i]
        ans = min(ans, abs(x[i]-y))
    
    print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
M = sum(a)
snk = 0
ans = float('inf')
for i in range(N-1):
    snk += a[i]
    ari = M - snk
    ans = min(ans,abs(snk-ari))
print(ans)

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

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

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    s = sum(a)
    c = 0
    m = float("inf")
    for i in range(len(a) - 1):
        c += a[i]
        m = min(m, abs(2 * c - s))
    print(m)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)


if __name__ == '__main__':
    main()

Solution (Python):
INF = 30000000000
N = int(input())
points = list(map(int, input().split()))
sums = [0]
for index in range(len(points)):
  sums.append(points[index]+sums[index])
ans = INF
last = sums[-1]
for s in sums[1:-1]:
  ans = min(ans, abs(last -s - s))
print(ans)

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

list = list(map(int, input().split()))
all = sum(list)
ans = 10**10
sunuke = 0

for i in range(0,n-1):
    sunuke += list[i]
    arai = all - sunuke
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)

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

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

MIN=10**10
for g in range(1,n):
    MIN=min(MIN,abs(accumlate[-1]-2*accumlate[g]))

print(MIN)

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

su = sum(a)
mini = 10**10
x = 0

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

    if diff < mini:
        mini = diff

print(mini)

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

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

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

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

print(ans)

Solution (Python):


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


cumulative_sum=["_"]*len(a_list)
cumulative_sum[0] = a_list[0]
for i in range(1,len(a_list)):
    cumulative_sum[i] = cumulative_sum[i-1] + a_list[i]

diff_list=[]
for v in cumulative_sum[:-1]:
    diff = abs( 2*v - cumulative_sum[N-1] )
    diff_list.append(diff)

print(min(diff_list))

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

first_half = l[0]
second_half = sum(l[1:])
diff = abs(first_half - second_half)

for i in l[1:len(l)-1]:
    first_half += i
    second_half -= i
    if abs(first_half - second_half) < diff:
        diff = abs(first_half - second_half)

print(diff)

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

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

x=[0]*N
y=[0]*N
z=[0]*N
for j in range(N):
    x[j]=b[j]
    y[j]=b[-1]-b[j]
    z[j]=abs(x[j]-y[j])

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

Solution (Python):
import itertools
n = int(input())
a_L = list(map(int,input().split()))

def get_ruisekiwa(a_L):
    
    return [0] + list(itertools.accumulate(a_L))

ans = float("inf")
r = get_ruisekiwa(a_L)


for i in range(1,len(a_L)):
    x = r[i]
    g = r[-1] - r[i]
    ans = min(abs(x-g),ans)

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from itertools import accumulate
ans=10**10
a=list(accumulate(a))
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()))
S = sum(a)
d = [0]*n
for i in range(1,n): d[i] += d[i-1]+a[i-1]
ans = [abs(S-2*d[i]) for i in range(1,n)]
print(min(ans))

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

sunuke=A[0]
araiguma=sum(A)-sunuke
ans=abs(sunuke-araiguma)

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

print(ans)

Solution (Python):
def main():
  n=int(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()

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

ans = 10**10
x = 0
y = sum(a)
for i in range(len(a)-1):
  x += a[i]
  y -= a[i]
  d = abs(x-y)
  if d < ans:
    ans = d
print(ans)

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

Solution (Python):
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A = list(accumulate(A))
answer = abs((A[-1] - A[0]) - A[0])
for i in range(N - 1):
    L = A[-1] - A[i]
    K = abs(L - A[i])
    if K < answer:
        answer = K


print(answer)

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

ans = float('inf')
x = 0
X = sum(a_l)
for a in a_l[:-1]:
    x += a
    ans = min(ans, abs(X - 2*x))

print(ans)

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

ans = 10**10
x = 0
y = sum(A)
for i in range(0,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()))
sum_a = sum(a)

ans = 10 ** 20
s_sum = 0
for i in range(n - 1):
    s_sum += a[i]
    ans = min(ans, abs((sum_a - s_sum) - s_sum))
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
B = [0]
C = [0]
for i in range(n):
    B.append(B[i] + A[i])
    C.append(C[i] + A[n-i-1])
ans = 10 ** 11
for i in range(1, n):
    if abs(B[i] - C[n-i]) < ans:
        ans = abs(B[i] - C[n-i])
print(ans)

Solution (Python):
def main():
  n = int(input())
  a = list(input_list())
  sa = sum(a)
  ans = 10**10
  r = 0
  for v in list(a)[:-1]:
    r += v
    ans = min(ans, abs(sa - (2*r)))
  print(ans)

def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

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

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

ans = 5e9
for i in range(1, N):
  p1 = cusum[i]
  p2 = cusum[-1] - cusum[i]
  diff = abs(p1 - p2)
  ans = min(diff, ans)

print(ans)

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

a_sum = [0]*N
x = 0

for i in range(N):
    x += a[i]
    a_sum[i] = x
    
ans = 10**18+1
sum_a = sum(a)

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

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
CS=[A[0]]
for i in range(1,N-1):
  CS.append(CS[-1]+A[i])
SUM=sum(A)
ans=10**20
for s in CS:
  ans=min(ans,abs(SUM-s-s))
print(ans)

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

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

total = sum(data)
x = 0
ans = 2 * 10**9 + 1
last = data[-1]
for i in range(len(data)-1):
    x += data[i]
    score = abs(2*x - total)
    if score < ans:
        ans = score
print(ans)

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

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

Solution (Python):
import itertools
n=int(input())
l=list(map(int,input().split()))
cul=list(itertools.accumulate(l))
sum=cul[-1]
tmp=abs(cul[0]-sum/2)
for i in range(1,n-1):
  if tmp>abs(cul[i]-sum/2):
    tmp=abs(cul[i]-sum/2)
print(int(2*tmp))

Solution (Python):
def main():
    import sys
    
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

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

if __name__ == '__main__':
    main()

Solution (Python):

n=int(input())
a=list(map(int,input().split()))
cs=[a[0] for _ in range(n)]
for i in range(n-1):
    cs[i+1]=cs[i]+a[i+1]
abs_cs=[abs(2*cs[i]-cs[-1]) for i in range(n-1)]
print(min(abs_cs))

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


s = sum(a)
m = pow(10, 20)
b = 0
for i in range(N-1):
    b += a[i]
    c = s - b
    
    
    if m > (abs(b-c)):
        m = abs(b-c)
    
print(m)

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    
    sum_A = sum(A)
    sub_sum = A[0]
    ret = abs(sum_A-2*sub_sum)
    for a in A[1:-1]:
        sub_sum += a
        if abs(sum_A-2*sub_sum) < ret:
            ret = abs(sum_A-2*sub_sum)
            
    print(ret)
    
solve()

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
from_left = [A[0]]
from_right = [A[-1]]

for i in range(1, N):
    from_left.append(from_left[-1]+A[i])
    from_right.append(from_right[-1]+A[N-i-1])
from_right.reverse()
ans = float('inf')
for i in range(N-1):
    ans = min(ans, abs(from_left[i]-from_right[i+1]))
print(ans)

Solution (Python):

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

def main():
    mod=10**9+7
    N=I()
    a=LI()
    S=[0]*(N+1)
    
    for i in range(N):
        S[i+1]=S[i]+a[i]
        
    ans=10**20
    for i in range(1,N):
        sn=S[i]
        ar=S[-1]-sn
        temp=abs(sn-ar)
        ans=min(ans,temp)
        
    print(ans)

main()

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

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

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

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]
ruiseki = [0] * n
ruiseki[0] = a[0]
for i in range(1, n):
    ruiseki[i] = ruiseki[i-1] + a[i]

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

total = ruiseki[n-1]
ans = 10000000000000
for i in range(1, n-1):
    ans = min(ans, abs((total - ruiseki[i]) - ruiseki[i]))
print(ans)

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

s = 0
l = sum(a)
r = []
for i in a[:-1]:
    s +=i
    k = abs(l-2*s)
    r.append(k)
r.sort()
print(r[0])

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sum_left,sum_right=a[0],sum(a)-a[0]
mi=abs(sum_left-sum_right)
for i in range(1,n-1):
    sum_left+=a[i]
    sum_right-=a[i]
    if abs(sum_left-sum_right)<mi: mi=abs(sum_left-sum_right)
print(mi)

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

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

Solution (Python):

def pin(type=int):
    return map(type,input().split())

"""
"""




N,=pin()
A=list(pin())
S=sum(A)
s=A[0]
m=abs(S-s*2)

for i in range(1,N-1):
    s=s+A[i]
    t=abs(S-s*2)
    
    m=min(t,m)
print(m)