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()))
r=sum(a)
l=0
ans=float('INF')
for i in range(n-1):  
    l+=a[i]
    r-=a[i]
    ans=min(ans,abs(l-r))
print(ans)

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

import itertools
accum = list(itertools.accumulate(a))

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

Solution (Python):
def main():
    card_num = int(input())
    cards = list(map(int, input().split()))
    answer = float("inf")
    num_sum = [cards[0]] * card_num
    for i in range(1, card_num):
        num_sum[i] = num_sum[i - 1] + cards[i]
    for i in range(card_num - 1):
        answer = min(answer, abs(2 * num_sum[i] - num_sum[-1]))
    print(answer)


if __name__ == '__main__':
    main()

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

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

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

cumsum = list(itertools.accumulate(a))

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

print(min_)

Solution (Python):
n = int(input())
lis = [int(x) for x in input().split()]
arai = sum(lis) - lis[0]
sunu = lis[0]
mn = abs(arai - sunu)

for i in lis[1:-1]:
    arai -= i
    sunu += i
    mn = min(mn,abs(arai - sunu))
print(mn)

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

x=[a[0]]

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



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

Solution (Python):
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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

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


ans = int(1e10)
for i in range(1,n):
    dif = abs(cum[i] - (cum[n]- cum[i]))
    if ans > dif:
        ans = dif
print(ans)

Solution (Python):
n = int(input())
lst1 = list(map(int,input().split()))
s = sum(lst1)
abs_ = 10**18
now = 0
i = 0
while True:
    now += lst1[i]
    if i >= n-1:
        break
    else:
        abs_ = min(abs_,abs(now-(s-now)))
    i += 1

print(abs_)

Solution (Python):
import itertools
import operator

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

cumsum = list(itertools.accumulate(a, operator.add))


s = cumsum[-1]
min_v = 10**10
for i in range(0, N - 1):
    x = cumsum[i]
    v = abs(2 * x - s)
    if v < min_v:
        min_v = v
print(min_v)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
s = 0
l = sum(A)
r = []
for a in A[:-1]:
  s += a
  k = abs(l - 2*s)
  r.append(k)
r.sort()
print(r[0])

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

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

y = sum(a)
x = 0
ans = 10000000000000000

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

print(ans)

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

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()
c = [0] * (n + 1)
for i in range(1, n + 1):
    c[i] = c[i - 1] + a[i - 1]

ans = inf
for i in range(n - 1):
    m = i + 1
    ans = min(ans, abs(c[m] - (c[n] - c[m])))

print(ans)

Solution (Python):
N = int(input())
tmp = [int(x) for x in input().split()]
lst = [tmp[0]]
for x in tmp[1:]:
    lst.append(lst[-1] + x)

total = lst[-1]
ret = 10 ** 100
for i in range(N - 1):
    n = lst[i]
    ret = min(ret, abs(n - (total - n)))
print(ret)

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

s = 0
t = 0

ans = 10 ** 12

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

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

print(ans)

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

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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

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

print(ans)

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

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

A=sum(a)
s=[0]*(n+1)
ans=float('inf')
for i in range(n-1):
    s[i+1]=s[i]+a[i]
    tem=abs(A-2*s[i+1])
    if tem>=0 and tem<ans:
        ans=tem
print(ans)

Solution (Python):

"""n = int(input())
l = list(map(int,input().split()))
sum_l = sum(l)
min_dif = abs(sum_l-2*l[0])
acum_sum = l[0]
for i in range(1,n-1):
    acum_sum += l[i]
    if min_dif > abs(sum_l - 2*acum_sum):
        min_dif = abs(sum_l - 2*acum_sum)

print(min_dif)"""
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]
ans = 5*10**9
for i in range(0,n-1):
  ans = min(ans,abs(cum_sum[n-1]-2*cum_sum[i]))
print(ans)

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

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

x = sum(A)
y = 0
res = 10 ** 18

for i in range(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()))
s = sum(a)
t = 0
ans = float("inf")
for k in range(N-1):
    t += a[k]
    s -= a[k]
    ans = min(ans,abs(s-t))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]
res = float("inf")
for i in range(1, N):
  res = min(res, abs(cs[i] - (cs[-1] - cs[i])))
print(res)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,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 fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    *cumsum, = accumulate(A)
    ans = inf
    for c in cumsum[:-1]:
        d = cumsum[-1] - c
        ans = min(ans, abs(d-c))
    print(ans)
if __name__ == '__main__':
    main()

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0]
for a in A:
    B.append(B[-1] + a)

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

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

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

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

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

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

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

    print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
sumA = 0
sumli = sum(a)
ans = 1000000000
for i in range(n-1):
    sumA += a[i]
    sumB = abs(sumli - sumA*2)
    ans = min(ans,sumB)
if n == 2:
    print(abs(a[0]-a[1]))
else:
    print(ans)

Solution (Python):
def splittingplie(n , a):

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

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

    return ans

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

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate

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

cumsum = list(accumulate(lst))

mi = 2 * 10 ** 9
su = cumsum[-1]
for i in range(len(cumsum)-1):
  mi = min(mi, abs(cumsum[i] - (su-cumsum[i])))
print(mi)

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

s = sum(a)
ans = 10**18
t = 0
l = 0
for i in range(N-1):
    t += a[i]
    l = s-t
    b = abs(t-l)
    ans = min(ans,b)

print(ans)

Solution (Python):
from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]
ac = list(accumulate(a))
d = float("inf")
for i in range(n - 1):
    d = min(abs(ac[i] * 2 - ac[-1]), d)
print(d)

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

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

sm=0
s_rui=[]
for tmp in a:
    sm+=tmp
    s_rui.append(sm)

a.reverse()
sm=0
a_rui=[]

for tmp in a:
    sm+=tmp
    a_rui.append(sm)
a_rui.reverse()

mn=10**10

for i in range(N-1):
    diff = abs(s_rui[i] - a_rui[i+1])
    if mn > diff:
        mn=diff

print(mn)

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

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

Solution (Python):

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

print(ans)

Solution (Python):

N=int(input())

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

sA=[A[0]]
siA=[A[-1]]

for i in range(N-1):
    sA.append(sA[i]+A[i+1])
    siA.append(siA[i]+A[-(i+2)])

ans=10**15

for i in range(N-1):
    ans=min(ans,abs(sA[i]-siA[-(i+2)]))



print(ans)

Solution (Python):

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

Solution (Python):
def solve(n, A):
    total = sum(A)
    x = A[0]
    ret = abs(2 * x - total)
    for i in range(1, n - 1):
        x += A[i]
        y = total - x
        if abs(x - y) < ret:
            ret = abs(x - y)
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

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

total = sum(a)

x = 0
arr = []
if n == 2:
    arr.append(abs(a[0]-a[1]))
else:
    for i in range(n-1):
        x += a[i]
        y = total - x
        arr.append(abs(x - y))

print(min(arr))

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
x = sum(A)-A[0]
y = 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):
N=int(input())
A=list(map(int,input().split()))
a=A[0]
b=sum(A)-A[0]
cnt=abs(a-b)
for i in range(1,N-1):
  a+=A[i]
  b-=A[i]
  c=abs(a-b)
  cnt=min(cnt,c)
print(cnt)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

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

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

sum_a = sum(A)
x = 0
ans = 1000000000000000

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

print(ans)

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

sum_a = sum(A)
x = 0
ans = 1000000000000000

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

print(ans)

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

Solution (Python):
import numpy as np
N = int(input())
a = list(map(int, input().split()))
res = np.cumsum(a)
ans = 1000000000000
for i in range(N-1):
    ans = min(ans, abs(res[-1]-res[i]*2))

print(ans)

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

sum_A = sum(A)
tot = 0
ans = float("inf")

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
arai = sum(A)
sunuke = 0
ans = 10000000000000000
for i in A[:-1]:
    arai -= i
    sunuke += i
    x = abs(sunuke - arai)
    if x < ans:
        ans = x
print(ans)

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

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

ans = abs(s - a)

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

print(ans)

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

csum1 = [A[0] for _ in range(N)]
for i in range(1,N):
  csum1[i] = csum1[i-1]+A[i]
csum2 = [A[-1] for _ in range(N)]
for i in range(N-2,-1,-1):
  csum2[i] = csum2[i+1]+A[i]

ans = float('inf')
for i in range(N-1):
  ans = min(abs(csum1[i]-csum2[i+1]),ans)
print(ans)

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

csum1 = [A[0] for _ in range(N)]
for i in range(1,N):
  csum1[i] = csum1[i-1]+A[i]
csum2 = [A[-1] for _ in range(N)]
for i in range(N-2,-1,-1):
  csum2[i] = csum2[i+1]+A[i]

ans = float('inf')
for i in range(N-1):
  ans = min(abs(csum1[i]-csum2[i+1]),ans)
print(ans)

Solution (Python):

"""
Created on Tue Jan 28 00:29:09 2020

@author: H_Hoshigi
"""
import sys

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





sunuke = 0
sum_a = sum(a_list)

min_difference = sys.maxsize



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

print(min_difference)

Solution (Python):

"""
Created on Tue Jan 28 00:14:43 2020

@author: H_Hoshigi
"""

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

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

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

print(min_difference)

Solution (Python):

n = int(input())
l = list(map(int,input().split()))
sum_l = sum(l)
min_dif = abs(sum_l-2*l[0])
acum_sum = l[0]
for i in range(1,n-1):
    acum_sum += l[i]
    if min_dif > abs(sum_l - 2*acum_sum):
        min_dif = abs(sum_l - 2*acum_sum)

print(min_dif)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a[i] for i in range(1, n))
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 sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)


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

print(ans)

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

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

A=list(accumulate(A))
max_= float("inf")

for a in A[:-1]:
    max_=min(max_,abs(A[-1]-2*a))
print(max_)

Solution (Python):
import sys
import itertools

input = sys.stdin.readline


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

    X = list(itertools.accumulate(A))
    Y = sum(A)

    ans = float("inf")
    for i in range(N - 1):
        x = abs(X[i] - (Y - X[i]))
        ans = min(ans, x)

    print(ans)



if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

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(abs(x - y), ans)

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]
    buff = abs(x - y)
    if buff < ans:
        ans = buff

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
answer = float('inf')
araisan_sum = sum(a) - a[0]
snuke_sum = a[0]
if len(a) == 2:
    answer = abs(snuke_sum - araisan_sum)
else:
    for i in range(1, n-1):
        snuke_sum += a[i]
        araisan_sum -= a[i]
        if answer >= abs(snuke_sum - araisan_sum):
            answer = abs(snuke_sum - araisan_sum)

print(answer)

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

all_sum = sum(nums)
accum = 0
ans = float('inf')
for i in range(N-1):
    accum += nums[i]
    ans = min(ans, abs(all_sum - 2 * accum))
print(ans)

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

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

ans = float("inf")
for i in range(1, N):
    ans = min(ans, abs(Sn[N]-Sn[i] - Sn[i]))

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

s = A[0]
a = sum(A)-A[0]
ans = abs(s-a)

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

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

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

ret = 10 ** 15

s = 0
t = sum(a)
a.pop()  
for x in a:
    s += x
    t -= x
    ret = min(ret, abs(s - t))

print(ret)

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
sum = 0
for i in range(N) :
    sum+=a[i]
ans = 2000000000
suma = 0
for i in range(N) :
    suma += a[i]
    d = abs(sum - 2 * suma)
    if i + 1 < N :
        ans = min(d,ans)
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    leftThanMe = [0 for _ in range(N+1)]
    rightThanMe = [0 for _ in range(N+1)]
    for i in range(N-1):
        leftThanMe[i+1] = A[i] + leftThanMe[i]
    for i in range(1, N)[::-1]:
        rightThanMe[i-1] = A[i] + rightThanMe[i]
    ans = inf
    for i in range(N-1):
        val = abs(leftThanMe[i] + A[i] - rightThanMe[i])
        ans = min(ans, val)
    print(ans)
main()

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


s = sum(a)
subsum = 0
res = 1001001001001001
for i in range(n-1):
    subsum += a[i]
    remain = s - subsum
    res = min(res, abs(remain-subsum))

print(res)

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

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[i-1]+a[i])

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

Solution (Python):

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

from operator import add
from itertools import accumulate

L = list(accumulate(A, add))

ans = float("inf")
for i in range(N-1):
  x = L[i]
  y = L[N-1] - L[i]
  ans = min(ans, abs(x-y))

print(ans)

Solution (Python):
import sys
from itertools import accumulate
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
sum_ls = [i for i in accumulate(a_ls[:-1])]
sum_a = sum(a_ls)
sum_ls.sort()
ind = bisect.bisect_left(sum_ls, sum_a / 2)
best = 10 ** 18
if ind < n - 1 and abs(sum_a / 2 - sum_ls[ind]) * 2 < best:
    best = abs(sum_a / 2 - sum_ls[ind]) * 2
if ind > 0 and abs(sum_a / 2 - sum_ls[ind - 1]) * 2 < best:
    best = abs(sum_a / 2 - sum_ls[ind - 1]) * 2
print(int(best))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=a[0]
y=sum(a)-a[0]
mini=float('inf')
if n==2:
    print(abs(a[0]-a[1]))
    exit()
for i in range(1,n-1):
    x+=a[i]
    y-=a[i]
    mini=min(mini,abs(x-y))
print(mini)

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

A_cum = A

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

A_cum_all = A_cum[-1]
ans = float('inf')

for i in range(n-1):
  x = A_cum[i]
  y = A_cum_all - x
  ans = min(ans, abs(x-y))
  
print(ans)

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

Solution (Python):
import numpy as np
N = int(input())
a = list(map(int,input().split()))
x = np.array([0]*(N))
suma = sum(a)
for i in range(1,N):
    x[i] = x[i-1] + a[i-1]
y = np.array([suma]*(N))-x
ans = list(map(abs,x-y))
print(min(ans[1:]))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
if N == 2:
  ans = abs(A[0]-A[1])
else:
  import numpy
  s = numpy.cumsum(A)
  sA = s[-1]
  ar = numpy.abs(sA-s-s)
  ans = min(ar[1:N-1])
print(ans)

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

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

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

Solution (Python):
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int64)

acum = a.cumsum()
total = acum[-1]
dif = np.abs(total-2*acum)
ans = dif[:-1].min()

print(ans)

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

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

Solution (Python):
from itertools import accumulate

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


ans = float('INF')
for i in range(n-1):
    if abs(acc[-1] - acc[i] * 2) < ans:
        ans = abs(acc[-1] - acc[i] * 2)
print(ans)

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

Solution (Python):
import numpy as np

N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
snuke = np.cumsum(A)[:-1]
kuma =  sum_A - snuke

ans = min(abs(snuke-kuma))
 
print(ans)

Solution (Python):
import numpy as np

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

snuke = np.cumsum(A)[:-1]
kuma =  np.cumsum(A[::-1])[:-1]

ans = min(abs(snuke-kuma[::-1]))

print(ans)

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

print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
s = sum(a)
snuke = 0
raccoon = s
ans = 10**15

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

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

Solution (Python):
from itertools import accumulate
n = int(input())
li = [int(x) for x in input().split()]
X = list(accumulate(li))

ans = float("inf")
for i in range(n-1):
    ans =min(ans ,abs(X[-1] - X[i]*2))
print(ans)

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

from itertools import accumulate

acum = list(accumulate(a))

answer = float("inf")
for i in range(N-1):
    answer = min(answer, abs(acum[-1]-acum[i]*2))

print(answer)

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

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

ans = 10**18
for i in range(N-1):
    left = a_cum[i]
    right = a_sum - a_cum[i]
    if abs(right - left) < ans:
        ans = abs(right - left)

print(ans)

Solution (Python):

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

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

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

    b = 1e+9
    j = 1
    
    while(j < n):
        if (abs(s[j] - (s[n] - s[j])) < b):
            b = abs(s[j] - (s[n] - s[j]))
        j += 1
    print(b)

Solution (Python):
import numpy as np
N=int(input())
X=[int(x) for x in input().split()]
Y=np.cumsum(X)
P=sum(X)
answer=float('inf')
for i in range(N-1):
  answer =min (answer,abs(P-2*Y[i]))
print(answer)

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

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