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

total = sum(a)
ans = None
x = 0
for ai in a[:-1]:
    x += ai
    total -= ai
    if ans is None:
        ans = abs(x - total)
    else:
        ans = min(ans, abs(x - total))

print(ans)

Solution (Python):


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

a=0
b=sum(A)

temp=10**12
for i in range(N-1):
    a+=A[i]
    b-=A[i]
    temp=min(abs(a-b),temp)

print(temp)

Solution (Python):
N = int(input())
I = list(map(int, input().split()))
minX = 10000000000
end = I.pop()
sumI = sum(I)
for i in range(len(I)):
  minX = min(minX, abs(sumI - end ) )
  popped = I.pop()
  sumI -= popped
  end += popped
  
print(minX)

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


if __name__ == '__main__':
    slove()

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

s = 0
for i in range(N):
    tmp = A[i]
    A[i] += s
    s += tmp

ans = None
for i in range(0, N - 1):
    a = A[-1] - A[i]
    b = A[i]
    if ans is None:
        ans = abs(a-b)
    else:
        ans = min(ans,abs(a-b))
print(ans)

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

S=[0]*(N-1)
T=[0]*(N-1)

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

T[-1]=A[-1]
for i in range(len(A)-2)[::-1]:
	T[i]=A[i+1]+T[i+1]

ans=-1
for i,j in zip(S,T):
	if ans==-1:ans=abs(i-j)
	else:ans=min(ans,abs(i-j))
print(ans)

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

ans=n*10**9
t=sum(a)

s=0

for i in range(n-1):

    s+=a[i]
    ans=min(ans,abs(t-2*s))
print(ans)

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

ans=n*10**9

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

for i in range(n-1):
    t_ans=abs(b[i+1]-(b[-1]-b[i+1]))
    ans=min(ans,t_ans)

print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
Sum = [A[0]]
Sum_card =sum(A)
Min= float('inf')
for i in range(1,N-1):
    Sum.append(Sum[-1]+A[i])
    Min = min(Min,abs(Sum[-1]-(Sum_card-Sum[-1])))
Min = min(Min,abs(Sum[-1]-(Sum_card-Sum[-1])))
print(Min)

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

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

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split(),dtype=np.int64)
c = A.cumsum()
s = c[-1]
d = np.abs(c-(s-c))
print(d[:-1].min())

Solution (Python):
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    ans =abs(a[0]-sum(a[1:]))
    s=0
    rac=sum(a)
    for i in a[:-1]:
        s+=i
        rac-=i
        if abs(s-rac)<ans:
            ans = abs(s-rac)
    print(ans)
if __name__ == '__main__':
    main()

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

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

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

print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = []
acu_r.append(A[-1])
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
  acu_r.append(acu_r[-1] + A[i])


ans = float("inf")
for i in range(N-1):
  ans = min(ans,abs(acu[i] - acu_r[N - (i + 2)]))
print(ans)

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

ans = float('inf')
snu = 0
ara = sum(A)
for a in A[0:-1]:
    snu += a
    ara -= a
    ans = min(ans, abs(snu - ara))
print(ans)

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

l=[-sum(a)]
for i in range(1,n):
    l.append(l[i-1]+a[i-1]*2)
l=l[1:]
for i in range(n-1):
    l[i]=abs(l[i])
print(min(l))

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

res = np.cumsum(a)

sum_a = np.sum(a)
ans = 100000000000
for i in range(N - 1):
    tmp = abs((sum_a - res[i]) - res[i])
    
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
cardNum = int(input())
card = list(map(int, input().split()))
allSum = 0
for i in range(cardNum):
  allSum += card[i]
halfwaySum = 0
for i in range(cardNum - 1):
  halfwaySum += card[i]
  if i == 0:
    mindiff = abs(allSum - 2 * halfwaySum)
  elif mindiff > abs(allSum - 2 * halfwaySum):
    mindiff = abs(allSum - 2 * halfwaySum)
print(mindiff)

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

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
L=[A[0]]
R=[A[-1]]
for i in range(1,n-1):
    l=L[i-1]+A[i]
    L.append(l)
    r=R[i-1]+A[-(i+1)]
    R.append(r)
c=2*10**14
for i in range(n-1):
    s=abs(L[i]-R[-(i+1)])
    c=min(c,s)
print(c)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
min_abs = 1000000000000000000000000
for i in range(1, n):
  A[i] += A[i-1]

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
A = sum(a)
ans = 100 ** 100
x = 0

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

print(ans)

Solution (Python):
from itertools import accumulate as ac
N = int(input())
A = list(ac(map(int,input().split())))
S = A.pop()
print(min(abs(S-2*a)for a in A))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
NOW=A[0]
ANS=abs(NOW-(S-NOW))
for i in range(1,N-1):
    NOW+=A[i]
    if abs(NOW-(S-NOW))<ANS:
        ANS=abs(NOW-(S-NOW))

print(ANS)

Solution (Python):
import numpy as np

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

A_diff = abs(sum(A) - 2 * A_cumsum)

A_diff = A_diff[:-1]

print(min(A_diff))

Solution (Python):






from sys import stdin,setrecursionlimit





setrecursionlimit(10**6)
input=stdin.readline

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

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

for i in range(N):
  Sf.append(Sf[i]+C[i])


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


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

Solution (Python):
N=int(input());a=list(map(int,input().split()))
sn=0;ar=sum(a);ans=10e16
for i in range(N-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()))

M=sum(A)
x0=0
D=abs(M-2*A[N-1])
for i in range(N-1):
    x0+=A[i]
    D=min(D,abs(M-2*x0))
print(D)

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

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

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

ans = float('inf')
s = sum(A)

x = A[0]
ans = min(ans, abs(2*A[0]-s))

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

print(ans)

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

ans = float('inf')
s = sum(A)
x = A[0]
y = s - x
d = abs(x-y)
ans = min(ans, d)

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

print(ans)

Solution (Python):

import math

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

total = sum(a_list)
work_list = []
sunuke = 0

for i in range(N - 1):
    sunuke += a_list[i]
    arai = total - sunuke
    work_list.append(abs(sunuke - arai))

ans = min(work_list)
print(ans)

Solution (Python):


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

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

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

print(ans)

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

sum_ = 0
min_ = float('inf')
for i in range(n-1):
    sum_ += li[i]
    diff = abs(total - 2*sum_)
    if diff < min_:
        min_ = diff
print(min_)

Solution (Python):
import itertools

n = int(input())
ls = list(map(int, input().split()))
accs = [0] + list(itertools.accumulate(ls))
res = float('inf')
for i in range(1, n):
    res = min(res, abs(accs[i] * 2 - accs[n]))
print(res)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
ruiseki = []
for i in range(N):
    if i == 0:
        ruiseki.append(a[i])
        continue
    else:
        ruiseki.append(ruiseki[-1] + a[i])
ans = abs(ruiseki[-1] - 2 * ruiseki[0])
for i in range(1, N-1):
    ans = min(ans, abs(ruiseki[-1] - 2 * ruiseki[i]))
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)
    for i in range(n-1):
        A[i+1]+=A[i]
    res=INF
    for x in A[:-1]:
        res=min(res,abs(s-2*x))
    print(res)
resolve()

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

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

s = [0]

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

s = s[1:]

ma = s[-1]

ans = 10 ** 9

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

print(ans)

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

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

s = [0]

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

s = s[1:]

ma = s[-1]

ans = 10 ** 18


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

print(ans)

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

Solution (Python):
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 10 ** 9 * n
    acc = 0
    s = sum(a)
    for i in range(n - 1):
        acc += a[i]
        diff = abs(s - 2 * acc)
        if diff < ans:
            ans = diff
    print(ans)


if __name__ == "__main__":
    resolve()

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

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    t = list(itertools.accumulate(a))
    print(min(abs(s-2*t[i]) for i in range(0, n-1)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    t = list(itertools.accumulate(a))
    print(min(abs(s-2*t[i]) for i in range(0, n-1)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    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)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    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)))


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [0] * N
x = sum(A)
y = 0
ret = abs(sum(A)- A[0] - A[0] )
for i, a in enumerate(A[:-1]):
  y += a
  x -= a
  ret = min(ret, abs(x - y))
print(ret)

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

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

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
sum_a = sum(a)
acc = list(itertools.accumulate(a))
ans = mod
if n == 2:
    print(abs(a[0] - a[1]))
else:
    for i in range(n-1):
        tmp = abs(acc[i] - (acc[-1]-acc[i]))
        ans = min(ans, tmp)
    print(ans)

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

Solution (Python):
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
ans = 10**18
lcums = np.cumsum(data)
rcums = list(reversed(np.cumsum(list(reversed(data)))))
for i in range(0,N-1):
    ans = min(ans,abs(lcums[i]-rcums[i+1]))
print(ans)

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

total=sum(A)
r=A[0]
ans=abs((total-r)-r)
for i in range(1,n-1):
  r+=A[i]
  ans=min(ans,abs((total-r)-r))
print(ans)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
acc = [0 for i in range(n)]
acc[0] = arr[0]

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

ans = 10000000000000
for i in range(n-1):
    l = acc[i]
    r = acc[-1]-acc[i]
    
    if abs(l-r) < ans:
        ans = abs(l-r)

print(ans)

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

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

tot = sum(A)

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

print(ans)

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

Solution (Python):
N = int(input())
A = [0] + list(map(int,input().split()))
A_sums = [0 for _ in range(N+1)]
A_sums_rev = [0 for _ in range(N+1)]

for idx in range(0,N-1):
  A_sums[idx+1] = A_sums[idx] + A[idx+1]

for idx in range(N-1,0,-1):
  A_sums_rev[idx] = A_sums_rev[idx+1] + A[idx+1]
  
print(min([abs(i-j) for i,j in zip(A_sums[1:-1],A_sums_rev[1:-1])]))

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

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

for i in range(1, N):
    if i == 1:
        x = sum(a[:i])
        y = sum(a[i:])
    else:
        x += a[i-1]
        y -= a[i-1]
    check = abs(x - y)
    if ans > check:
        ans = check

print(ans)

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

sum_list = [0]
sum_a = sum(a)

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

min_a = 3*10**9    
for i in sum_list[1:]:
    abs_a=abs(sum_a-2*i)
    if min_a>abs_a:min_a=abs_a
print(min_a)

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

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

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

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

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
su=sum(a)
ans=float('inf')
check=a[0]
for i in range(1,n):    
    check2=su-check
    ans=min(ans, abs(check-check2))
    check+=a[i]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
x = A[0]
y = sum(A[1:])
ans = 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]
    ans = min(ans, abs(x-y))
print(ans)

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


print(mn)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
li = [A[0]]+[0]*(N-1)
min = 10**18
for i in range(1,N):
    li[i] = li[i-1]+A[i]
for j in range(N-1):
    tmp = abs(li[j]-(li[-1]-li[j]))
    if tmp<min:
        min = tmp
print(min)

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

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

min_s = float('inf')
x = 0
for i in range(n-1):
  x += l[i]
  s = abs(a-2*x)
  if s <= min_s:
    min_s = s
print(min_s)

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

min_s = float('inf')
x = 0
for i in range(n-1):
  x += l[i]
  s = abs(a-2*x)
  if s <= min_s:
    min_s = s
print(min_s)

Solution (Python):
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Solution (Python):

N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)
sum_a = tmp - sum_s
ans = abs(sum_s - sum_a)

for i in range(1,N):
    sum_a = tmp - sum_s
    if ans > abs(sum_s - sum_a):
        ans = abs(sum_s - sum_a)
        sum_s += a[i]
    else:
        sum_s += a[i]
print(ans)

Solution (Python):

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

ans = float("inf")
snu = 0
ara = sum(A)
for i in range(n-1):
    snu += A[i]
    ara -= A[i]
    ans = min(ans, abs(snu - ara))

print(ans)

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

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

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

x = 0
z = sum(A)

ans = 10 ** 14

for i in range(N-1):
    x += A[i]
    tmp = abs(2 * x - z)
    if ans > tmp:
        ans = tmp

print(ans)

Solution (Python):
_ = input()
A = list(map(int, input().strip().split(' ')))

sum_all = sum(A)
s = 0
ans = float('inf')
for i in range(len(A)-1):
  s += A[i]
  ans = min(ans, abs(sum_all-2*s))
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]
diff = np.abs(Acum - (total-Acum))

answer = diff[:-1].min()

print(answer)

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


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


s = sum(A) 


h = s/2
m = 10000000000
index = 0

for i in range(N-1):
  if abs(S[i] - h) < m:
    m = abs(S[i] - h)
    index = i
    
print(abs(s-S[index]*2))

Solution (Python):
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



n = I()
nums = LI()
s = sum(nums)
cumsum = list(accumulate(nums))
ret = float('inf')
for i in range(len(cumsum) - 1):
    ret = min(ret, abs(cumsum[i] - (s - cumsum[i])))



print(ret)

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

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

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

a_rui = []

tmp = 0

for i in range(n):
    tmp += a[i]
    a_rui.append(tmp)
    
ans = 10**20

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

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

sunuke=a[0]
kuma=sum(a[1:])
ans=abs(sunuke-kuma)

for i in range(1, n-1):
    sunuke+=a[i]
    kuma-=a[i]
    ans=min(ans, abs(sunuke-kuma))

print(ans)

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

Solution (Python):
from itertools import accumulate
N = int(input())
A = [int(s) for s in input().split()]
S = list(accumulate(A))
ans = min([abs(2 * S[i] - S[N-1]) for i in range(N-1)])
print(ans)

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

forward = [0] * (N - 1)
backward = [0] * (N - 1)


f = 0
for _ in range(N-1):
    f += a[_]
    forward[_] = f

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

diff = [abs(fi - bi) for fi, bi in zip(forward, backward)]

print(min(diff))

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

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

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    v = 0
    tot = sum(A)
    min_d = float('inf')
    for i in range(N-1):
        v += A[i]
        min_d = min(min_d, abs(tot - 2*v))

    return min_d

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

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

s = sum(a)
s1 = 0
ans = 10**15
for i in range(n-1):
    s1 += a[i]
    ans = min(ans, abs(s1 - (s-s1)))

print(ans)

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=[0]*200000
total=0
mini=1000000000000000000
for i in range(N):
    total+=A[i]
    B[i]=total

for i in range(N-1):
    if abs(B[i]-(B[N-1]-B[i]))<mini:
        mini=abs(B[i] - (B[N - 1] - B[i]))
print(mini)

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

S = sum(A)
ans = 10**11

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

print(min(abs(S-2*X[i]) for i in range(1,N)))

Solution (Python):



import numpy as np
import sys
input = sys.stdin.readline


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

    SUM = sum(a)

    ans = list()
    left = a[0]
    for i in range(1, n):
        ans.append(abs(2 * left - SUM))
        left += a[i]

    print(min(ans))


if __name__ == '__main__':
    main()

Solution (Python):

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

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



before = 10**9*2
for i in range(N-2, -1, -1):
    left = S[i]
    right = S[N-1] - left
    diff = abs(right - left)
    before = min(before, diff)

print(before)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A)

cs1 = A.cumsum()
cs2 = A[::-1].cumsum()[::-1]
a = abs((cs1[:-1] - cs2[1:])).min()
print(a)

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

x, y = 0, sum(a)
m = float('inf')

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

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

Solution (Python):
n = int(input())
an = [int(x) for x in input().split()]
an_sum = sum(an)
x_sum = 0
ans = 1e10
for x in range(0,n-1):
    x_sum += an[x]
    ans = min(ans, abs(an_sum-2*x_sum))
print(ans)

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

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

all_sum = sum(A)
ans = 10**20
for i in range(0,N-1):
	sunuke = sum_list[i]
	araiguma = all_sum - sum_list[i]
	ans = min(ans,abs(sunuke - araiguma))

print(ans)

Solution (Python):
from bisect import bisect_left


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


cumsum = []
ret = 0


for i in (nums):
    ret += i
    cumsum.append(ret)


s = cumsum[-1]


min_val = float('inf')


for i in range(len(cumsum)-1):
    min_val = min(min_val, abs(cumsum[i] * 2 - s))




print(min_val)

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

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

ans = float('inf')
left = 0
right = sum(A)

for a in A[: N - 1]:
    left += a
    right -= a
    ans = min(ans, abs(left - right))

print(ans)

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

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