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):
import sys
input = sys.stdin.readline

N = int(input())
A = [int(v) for v in input().split()]
p = sum(A)
L = [0] * (N + 1)

for i in range(N):
    L[i + 1] = L[i] + A[i]

ans = 10 ** 18
for i in range(N - 1):
    t = L[i + 1] - L[0]

    ans = min(ans, abs(t - p + t))

print(ans)

Solution (Python):
from itertools import accumulate
N, *a = map(int, open(0).read().split())
x = list(accumulate(a[:-1]))
y = list(accumulate(a[:0:-1]))[::-1]
print(min(abs(i - j) for i, j in zip(x, y)))

Solution (Python):

N = int(input())
cards = list(map(int,input().split(" ")))
ruiseki = [cards[0]]
su  = sum(cards)
for i,card in enumerate(cards[1:-1]): 
    ruiseki.append(ruiseki[i]+card)

ans = 10e15
for temp  in ruiseki:
    x = temp
    y = su - temp
    cand = abs(x-y)
    if cand < ans:
        ans = cand

print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(0,n-1):
    ans=min(ans,abs(mae[i]-usi[i+1]))
    
print(ans)

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

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

b = []

t = 0
for aa in a:
    t += aa
    b.append(t)
s = b[-1]

ans = 100000000000000000

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

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

print(ans)

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

Solution (Python):
from itertools import accumulate
N = int(input())
a = list(map(int,input().split()))
acc = list(accumulate(a))
m = float("inf")
for i in range(0, N-1):
    x = acc[i]
    y = acc[-1]-x
    m = min(abs(x-y), m)
print(m)

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

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

arr_sum = sum(arr)

temp_sum = 0
ans_arr = []
for i in arr:
    temp_sum += i
    ans_arr.append(abs(arr_sum - temp_sum * 2))

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

Solution (Python):


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

    
    
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    for i in range(1, N):
        ruiseki[i] = ruiseki[i-1] + A[i]
    
    min_diff = float("inf") 
    for i in range(0, N-1):
        x = ruiseki[i]
        y = ruiseki[N-1] - ruiseki[i]
        min_diff = min(min_diff, abs(x-y))
    
    print(min_diff)

if __name__ == "__main__":
    solve()

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

ans = 10**40
CS = [0] * (N+1)

for i in range(N):
    CS[i+1] = CS[i] + A[i]

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

print(ans)

Solution (Python):
n=int(input())
a_list=[int(i) for i in input().split()]
total=sum(a_list)
diff=sum(abs(a_list[i]) for i in range(n))
left=0
for i in range(n-1):
    left+=a_list[i]
    right=total-left
    diff=min(diff,abs(left-right))
print(diff)

Solution (Python):


import math


N = int(input())
An = list(map(int, input().split()))
sm = [0, sum(An)]

ans = abs(An[0] - sum(An[1:]))
for i in range(N-1):
  sm[0] += An[i]
  sm[1] -= An[i]
  ans = min(ans, abs(sm[0]-sm[1]))
print(ans)

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

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

Solution (Python):
inf = float('inf')

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

sum_A = sum(A)
ans = inf
res = 0

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

print(ans)

Solution (Python):
N = int(input())
lst_a = list(map(int, input().split()))
total = sum(lst_a)
x = 0
ans = float("INF")


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


print(ans)

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

goukei = sum(a)

x = 0 
ans = 10 ** 16
for i in range(N-1):
    x += a[i]
    ans = min(ans, abs(goukei - 2 * x))

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
C = []
num = 0
for i in range(N):
    num += A[i]
    C.append(num)
A.reverse()
D = []
num = 0
for i in range(N):
    num += A[i]
    D.append(num)
D.reverse()
ans = float('inf')
for i in range(0, N - 1):
    ans = min(ans, abs(C[i] - D[i + 1]))
print(ans)

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

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

Solution (Python):

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

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

s = sum(a)



x = [a[0]]*(N-1)

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

print(min(map(lambda y:abs(2*y-s),x)))

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    INF = int(1e15)
    ans = INF
    acc = 0
    for i in range(len(A) - 1):
        acc += A[i]
        ans = min(ans, abs(total - 2 * acc))

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [0 for i in range(n)]
b[0] = a[0];
for i in range(1, n) :
    b[i] = b[i-1]+a[i]
tot = b[n-1]
ans = 10000000000
for i in range(0, n-1) :
    x = b[i]
    y = tot - x
    if abs(x-y) < ans :
        ans = abs(x-y)
print(ans)

Solution (Python):
from itertools import accumulate

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

*B, su = list(accumulate(A))
print(min(abs(su - 2 * b) for b in B))

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

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

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

l, r = A[0], sum(A[1:])
mi = abs(l - r)
for a in A[1:N - 1]:
    l, r = l + a, r - a
    mi = min(mi, abs(l - r))
print(mi)

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())
a = list(map(int, input().split()))
sum = sum(a)
x = 0
y = sum
min_d = float('inf')
for i in range(N-1):
  x += a[i]
  y -= a[i]
  if abs(x-y) < min_d:
    min_d = abs(x-y)
print(min_d)

Solution (Python):
from collections import Counter
from functools import reduce

import bisect
import copy
import fractions
import math
import pprint
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    
    x = root(x)
    y = root(y)
    if x == y:
        return
    
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  
        return x
    else:
        node[x] = root(node[x])  
        return node[x]
def dfs(v):
    
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  
            continue
        if visited[v2] == True:  
            continue
        dfs(v2)


n, a = II(), LI()
ruiseki = [0] * n
ruiseki[0] = a[0]
allsum = sum(a)
if n == 2:
    print(abs(a[0] - a[1]))
    exit()

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

mini = INF
for i in range(0, n-1):
    
    mini = min(mini, abs(2 * ruiseki[i] - allsum))

print(mini)

Solution (Python):

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def submit():
    n, alist = read_input()

    total = sum(alist)

    s = 0
    mindiff = float('inf')
    for i in range(n - 1):
        s += alist[i]
        rest = total - s

        diff = abs(s - rest)
        if diff < mindiff:
            mindiff = diff

    print(mindiff)

if __name__ == '__main__':
    submit()

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("Heisei")
    else:print("TBD")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


n = ip()                              



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







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

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

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

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

sumA = nums[-1]
ans = 10**20
for a in nums[1:-1]:
    p = abs(2*a-sumA)
    ans = min(ans, p)
print(ans)

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

Solution (Python):
def c_splitting_pile(N, A):
    
    
    from itertools import accumulate
    total = sum(A)
    return min([abs(total - 2 * x) for x in accumulate(A[:-1])])

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

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

l = [0] * (N+1)
r = [0] * (N+1)

for i in range(N):
    l[i+1] = l[i] + a[i]

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

res = []

for i in range(1,len(l)-1):
    res.append(abs(l[i]-r[i]))

print(min(res))

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n  = f()[0]
    a = f()

    s = [0] * n
    for i in range(n):
        s[i] = a[i] + (s[i-1] if i>0 else 0)

    mina = abs(s[n-1]-2*s[0])

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

solve()

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

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

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

S = sum(a)

ans = 10 ** 18
x = 0
for i in range(N-1):
    x += a[i]
    ans = min(ans, abs((S-x)-x))

if N == 2:
    ans = abs(a[0]-a[1])
print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

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

sum_a = sum(a)

ans = 10**10
x = 0
for i in range(N-1):
    x += a[i]
    ans = min(ans,abs(sum_a-2*x))

print(ans)

Solution (Python):
N = int(input())
sum_a = []
a = [int(i) for i in input().split()]
tmp = 0
for i in a:
    tmp += i
    sum_a.append(tmp)

for i in range(N-1):
    if i == 0:
        ans = abs(sum_a[i] - (tmp - sum_a[i]))
    else:
        ans = min(ans, abs(sum_a[i] - (tmp - sum_a[i])))

print(ans)

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

b = sum(a)
c = [0] * (N+1)

for i in range(N):
    c[i+1] = c[i] + a[i]

ans = int(3e9)
for i in range(1, N):
    score = abs(c[i]-(b-c[i]))
    if ans > score:
        ans = score

print(ans)

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

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input().rstrip())
    a = list(int(_) for _ in input().split())
    sum_p = 0
    sum_q = sum(a)
    r = INF
    for i in range(N-1):
        sum_p += a[i]
        sum_q -= a[i]
        r = min(r,abs(sum_p-sum_q))
    print(r)
    
if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
Asum = sum(A)
ans = 10**10
x = 0
for i in range(N-1):
    x+=A[i]
    ans = min(ans, abs(Asum-2*x))
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
tmp = 0
ans = 10 ** 10
Asum = sum(A)
for i in range(N - 1):
    tmp += A[i]
    a = abs((Asum - tmp) - tmp)
    if ans > a:
        ans = a
print(ans)

Solution (Python):


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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
x = a[0]
y = 0
for i in range(1, n):
    y += a[i]
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):
import functools

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

def append_to_partial_sums(array, a_i):
    array.append((0 if len(array) == 0 else array[-1]) + a_i)
    return array

snuke = list(functools.reduce(append_to_partial_sums, a, []))
raccoon = list(reversed(functools.reduce(append_to_partial_sums, reversed(a), [])))
print(min(abs(snuke[i - 1] - raccoon[i]) for i in range(1, n)))

Solution (Python):
import itertools

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

B = list(itertools.accumulate(A))
ans = 10000000000
for i in range(N-1):
    if ans > abs(B[-1] - 2*B[i]):
        ans = abs(B[-1] - 2*B[i])

print(ans)

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

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

sum_a = sum(a)


left = a[0]
right = sum_a - left
delta_min = abs(left - right)
left_ = left


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

    delta = abs(left - right)

    delta_min = min(delta_min, delta)
 
    left_ = left

print(delta_min)

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

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

total = sum(a)
x = 0
ans = float("inf")
for i in range(n-1):
  x += a[i]
  y = total - x
  if(abs(x-y) < ans):
    ans = abs(x-y)
    
print(ans)

Solution (Python):
import bisect
n=input()
a=list(map(int,input().split()))
if n=="2":print(abs(a[0]-a[1]))
else:
    s=[]
    x=0
    for i in a[:-1]:
        x+=i
        s.append(x)
    s.sort()
    s.append(float("inf"))
    y=bisect.bisect_left(s,sum(a)/2)
    print(min(abs(sum(a)-2*s[y]),abs(sum(a)-2*s[y-1])))

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

ta = []
S = 0
for ai in a:
    S += ai
    ta.append(S)
ans = 10 ** 16
for i in range(len(ta) - 1):
    ans = min(ans, abs(S - 2 * ta[i]))

print(ans)

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(input())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
A=LI()

Aac=[A[0]]

for aidx in range(1,N):
	Aac.append(Aac[aidx-1]+A[aidx])
ans=10**18
for a in Aac[:-1]:
	ans=min(ans,abs((Aac[-1]-a)-a))
print(ans)

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
summ = sum(a) - a[0]
sunn = a[0]
minn = abs(summ - sunn)
for i in range(1, n - 1):
    summ -= a[i]
    sunn += a[i]
    minn = min(minn, abs(summ - sunn))
print(minn)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
wa=sum(a)
curmin=100000000000000000000000000000
cursum=0
a.pop()
for card in a:
    cursum+=card
    curmin=min(curmin,abs(wa-2*cursum))
print(curmin)

Solution (Python):
n = int(input())
s = [ int(i) for i in input().split() ]
t = sum(s)
curr = 0
ans = 1e18
for i in range(n-1):
    curr += s[i];
    ans = min( ans, abs((t-curr)- curr));
print(ans)

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

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

s = 0

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

a = data[-1]
res = -1
for i in range(n-1):
    if res<0:
        res = abs(data[i]-(a-data[i]))
    else:
        res = min(res,abs(data[i]-(a-data[i])))
print(res)

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

p1 = 0
p2 = sum(A)
diff = 9999999999999999
for i in range(N-1):
    p1 += A[i]
    p2 -= A[i]
    diff = min(diff, abs(p1-p2))

print(diff)

Solution (Python):
from itertools import accumulate
n = int(input())
a = [int(item) for item in input().split()]
cumsum = list(accumulate(a))

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

print(ans)

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
X=sum(A)
x=0
ans=10**10
for i in range(len(A)):
    x+=A[i]
    if i+1<N:
        ans=min(ans,abs(X-2*x))
print(ans)

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

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

print(min)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
lst=[0]
for i in l:
    lst.append(lst[-1]+i)
sm=lst[-1]
ans=10**20
for i in range(1,n):
    x=lst[i]
    y=sm-x
    a=abs(x-y)
    ans=min(ans,a)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
S = sum(a)
f, m = 0, 10**20
for i in range(N - 1):
    f += a[i]
    m = min(abs(S - 2 * f), m)
print(m)

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

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

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
t = (sum(a))
x = t
ans = 10 ** 10
for ai in a[:-1]:
    x -= 2 * ai
    if ans > abs(x):
        ans = abs(x)
print(ans)

Solution (Python):
import sys
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    B = list(accumulate(A))

    total = sum(A)
    ans = float('inf')
    for b in B[:N-1]:
        ans = min(ans, abs((total - b) - b))

    return ans



if __name__ == '__main__':
    print(main())

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

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

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

Solution (Python):


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

X = sum(a)

minsum = 10000000000

cnt = 0

for i in range(1,n):
    cnt += a[i-1]
    minsum = min(minsum,abs(X-2*cnt))

print(minsum)

Solution (Python):
N = int(input())
alist = list(map(int,input().split()))
ans = 10 ** 10
cnt = 0
asum = sum(alist)
for a in alist[:-1]:
    cnt += a
    diff = abs(asum - 2 * cnt)
    if ans > diff:
        ans = diff
print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
Sum=sum(a)
ans=10**18
cnt=0
for i in a[:n-1]:
    cnt+=i
    diff=abs(Sum-2*cnt)
    if ans>diff:
        ans=diff
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
ans = 10**20
x = A[0]

for a in A[1:]:
    n = total - x
    ans = min(ans, abs(n-x))
    x += a
print(ans)

Solution (Python):
def splitting_pile(N: int, A: list)->int:
    snuke, raccoon = A[0], sum(A[1:])

    min_diff = abs(snuke-raccoon)
    for a in A[1:-1]:
        snuke += a
        raccoon -= a
        min_diff = min(min_diff, abs(snuke-raccoon))

    return min_diff


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = splitting_pile(N, A)
    print(ans)

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

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

Solution (Python):
import numpy as np

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

sumA = A.sum()

print(np.abs(2*np.cumsum(A) - sumA)[:-1].min())

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

Solution (Python):
import sys

N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=sys.maxsize

for i in range(N):
  L[i+1]=L[i]+A[i]

for i in range(1,N):
  x = L[i]
  y = L[-1] - L[i]
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

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

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

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

import numpy
res = numpy.cumsum(A)
sum_A = sum(A)

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

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

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

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

A=list(map(int,input().split()))
sa=sum(A)-2*A[0]
S=[abs(sa)]
if n>2:
    for i in range(1,n-1):
        sa-=2*A[i]
        S.append(abs(sa))
    print(min(S))
         
else:
    a=A[0]
    b=A[1]
    print(abs(a-b))

Solution (Python):
N = int(input())
a =[int(_) for _ in input().split()]
ans = 10**15
cardsum = sum(a)
ruiseki = [0]

for i in range(N-1):
    ruiseki.append(ruiseki[i]+a[i])
    snuke = ruiseki[i+1]
    arai = cardsum - snuke
    diff = abs(snuke - arai)
    if diff < ans:
        ans = diff

print(ans)

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

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
ans = 100000000000
SUM = sum(a)
for i in b[:-1]:
  tmp = abs(SUM - i * 2)
  if tmp < ans:
    ans = tmp
print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
su=sum(l)
l.pop()
a=0
x=99999999999999999999
for i in l:
  a+=i
  b=su-a
  c=abs(a-b)
  if c<x:
    x=c
print(x)

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

A_sum = sum(A)
check = 0
ans = 10 ** 18
for i in range(N-1):
    check += A[i]
    ans = min(abs(check - (A_sum - check)), ans)
print(ans)

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

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

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

y = sum(a) - a[0]
x = a[0]
min_diff = abs(x-y)

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

print(min_diff)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
S = sum(A)
res = []
Sa = 0
for a in A[:-1]:
        Sa += a
        res.append(abs(2*Sa-S))

print(min(res))

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

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

sm = sum(li_a)

li_ruiseki = list()

for a in li_a:
    if len(li_ruiseki) == 0:
        li_ruiseki.append(a)
    else:
        li_ruiseki.append(li_ruiseki[-1] + a)

result = -1
for x in li_ruiseki[:-1]:
    a = abs(sm - 2 * x)
    result = min(result, a) if result >= 0 else a

print(result)

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


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

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):
N = int(input())
a = list(map(int,input().split()))
A = sum(a)
ans = float("inf")
p = 0
for i in range(N-1):
    p += a[i]
    if abs(2*p - A) < ans:
        ans = abs(2*p-A)

print(ans)

Solution (Python):
N=int(input())
lst=[int(i) for i in input().split()]
import numpy
res=numpy.cumsum(lst)
ans=10e20
for i in range(N-1):
  ans=min(ans,abs(res[i]-(res[-1]-res[i])))
print(ans)

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

max_ = sum(A)
tmp = 0
result = []
for i in range(N-1):
  tmp += A[i]
  result.append(abs(max_-2*tmp))
print(min(result))

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    ans = float("inf")
    x = 0
    for i in range(N-1):
        x += A[i]
        ans = min(ans, abs(total - 2*x))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


def nibutan(list,n):
	left = 0
	right = len(list)
	while left+1 != right:
		middle = (left+right)//2
		if list[middle] <= n:
			left = middle
		else:
			right = middle
	return right

N = I()
l = IL()
tmp = l[0]

suml = [tmp]
for i in range(1,N):
	tmp += l[i]
	suml.append(tmp)

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

print(ans)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






n = I()
a = LI()
b = [None for i in range(n-1)]
for i in range(n-1):
    a[i+1] += a[i]
for i in range(n-1):
    b[i] = abs(2*a[i]-a[n-1])
print(min(b))

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()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))