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()))
S = sum(A)
T = [0]*(N+1)
for i in range(N):
  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())
L = list(map(int,input().split()))

li = [0]

for i in range(n):
    li.append(li[i]+ L[i])

sumL = sum(L)

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

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    cumA = np.cumsum(A)
    total = cumA[-1]
    ans = 10 ** 10000
    for a in cumA[:-1]:
        ans = min(ans, abs(a - (total - a)))
    print(ans)


if __name__ == '__main__':
    main()

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

lsum = a[0]
rsum = sum(a[1:])
ans = abs(lsum - rsum)

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

    if res < ans:
        ans = res

print(ans)

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ans = float('inf')
l = 0
r = sum(a)

for i in range(N - 1):
    l += a[i]
    r -= a[i]
    ans = min(ans, abs(r - l))
    
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(ans,abs(x-y))
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())

left=a[0]
right=sum(a)-a[0]
ans=abs(left-right)
for i in range(1,n-1):
    left+=a[i]
    right-=a[i]

    ans=min(ans,abs(left-right))

print(ans)

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

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

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

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

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

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

cum=[0]
for i in range(N):
  cum.append(cum[-1]+a[i])
  
ans=10**20
for i in range(1,N):
  tmp = abs(cum[-1]-cum[i]-cum[i])
  ans = min(ans, tmp)
  
print(ans)

Solution (Python):














INF = pow(10,10)

def solve(n,a):
  res = INF
  x = 0
  y = sum(a)
  for i in range(n-1):
    x += a[i]
    y -= a[i]
    res = min(res,abs(x-y))
  return res



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

if __name__ == '__main__':
  main()

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

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

ans=[]
for y in range(n-1):
  ans.append(abs((rui[n-1]-rui[y])-rui[y]))
  
print(min(ans))

Solution (Python):
from itertools import accumulate
N = int(input())
A = tuple(accumulate(map(int, input().split())))
x = A[-1]
y = A[0]
ans = abs(x - y - y)
for a in A[:-1]:
    ans = min(ans, abs(x - a - a))
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
left = 0
right = sum(A)
MIN = float('inf')
for i in range(n-1):
    left += A[i]
    right -= A[i]
    
    MIN = min(MIN,abs(left - right))
print(MIN)

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

sum_a=sum(a)
ans = 10**11
x=0
for i in range(N-1):
    x += a[i]
    diff = abs(sum_a - 2 * x)
    if diff<ans:
        ans=diff


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):
    a = A[i]
    x += a
    y -= a
    dif = abs(x - y)
    if dif < ans:
        ans = dif
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
sunuke = 0
arai = sum(a)
p = []
for i in range(len(a)-1):
  sunuke += a[i]
  arai -= a[i]
  p.append(abs(sunuke - arai))

print(min(p))

Solution (Python):
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    acc_A = []
    acc = 0
    for a in A:
        acc += a
        acc_A.append(acc)

    minv = 10e10
    for i in range(0, N-1):
        minv = min(abs(acc_A[i]-(acc_A[-1]-acc_A[i])), minv)
    print(minv)

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

Solution (Python):
def main():
    n = int(input())
    A = [int(i) for i in input().split()]
    cul_sum = [0] * (n + 1)

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

    ans = float("inf")

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    B = list(itertools.accumulate(A, initial=0))
    s = 0
    ans = 10 ** 12
    for i in range(N - 1, 0, -1):
        s += A[i]
        ans = min(ans, abs(s - B[i]))

    return ans


print(solve())

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0 for _ in range(N+1)]
for i in range(1,N+1):
    B[i] = B[i-1]+A[i-1]
cmin = 10**15
for i in range(1,N):
    cmin = min(cmin,abs(2*B[i]-B[N]))
print(cmin)

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

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

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

for ai in a:
    acc.append(acc[-1]+ai)

ans = 10**18

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

print(ans)

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

S = sum(A)

from itertools import accumulate
C = [0]+A
C = list(accumulate(C))
ans = 10**18
for i in range(1, n):
    s = C[i]
    a = S-s
    ans = min(ans, abs(s-a))
print(ans)

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

accum = []
csum = 0
for a in al:
    csum += a
    accum.append(csum)

asum = accum[-1]
ans = 10**10
for a in accum[:-1]:
    x = a
    y = asum-x
    ans = min(ans, abs(x-y))

print(ans)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

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

ans = INF
for i in range(1, n):
    now = abs(acc[i] - acc[0] - (acc[n] - acc[i]))
    ans = min(ans, now)
print(ans)

Solution (Python):
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = list(accumulate(A))
    minimum = 10**18
    for i, c in enumerate(S):
        if i == N - 1: continue
        minimum = min(minimum, abs(2 * c - S[-1]))
    print(minimum)

if __name__ == "__main__":
    main()

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

S=sum(A)

X=0
D=float("inf")
for i in range(N):
    X+=A[i]

    if i!=N-1:
        Y=S-X
        D=min(D,abs(X-Y))
print(D)

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

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

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

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

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

f=0
b=sum(a)
m=abs(a[0]-sum(a[1:]))
for i in range(n-1):
    f+=a[i]
    b-=a[i]
    m=min(m,abs(f-b))
print(m)

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

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

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

all_sum = sum(nums)
sums = [None] * N

min_diff_value = float('inf')
min_diff_index = -1


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

    lhs_value = sums[i]
    rhs_value = all_sum - lhs_value
    diff_value = abs(lhs_value - rhs_value)

    if diff_value < min_diff_value:
        min_diff_value = diff_value

print(min_diff_value)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from itertools import accumulate

cum = list(accumulate(As))
ans = 10**18
for i in range(N-1):
    ans = min(ans, abs(cum[i]-(cum[-1]-cum[i])))
print(ans)

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

ans=2*10**9+10
s=sum(a)
now=0
snuke=0
for i in range(N-1):
    snuke+=a[i]
    now=s-2*snuke

    ans=min(abs(now),ans)

print(ans)

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

Solution (Python):
import math

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

m = 10**10
x = 0
X = sum(a)

for i in range(n):
    x += a[i]
    if i+1 < n:
        m = min(m, abs(X-2*x))

print(m)

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

minint = 10**9

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

else:
    s1 = s1 = sum(a[0:1])
    s2 = sum(a[1: N])
    for i in range(1, N - 1):
        s1 += a[i]
        s2 -= a[i]
        
        minint = min(minint, abs(s1 - s2))

    print(minint)

Solution (Python):
from itertools import accumulate

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

B = list(accumulate(A))
p = B[-1]
ans = 10**12
for i in range(N-1):
    ans = min(ans,abs(p-2*B[i]))

print(ans)

Solution (Python):
N = int(input())
A = [int(T) for T in input().split()]
L = [0]*(N+1)
R = [sum(A)]*(N+1)
for T in range(0,N):
    L[T+1] = L[T]+A[T]
    R[T+1] = R[T]-A[T]
MIN = 10**10
for T in range(1,N):
    if abs(L[T]-R[T])<MIN:
        MIN = abs(L[T]-R[T])
print(MIN)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()

suma = sum(a)
ans = float("inf")
t = 0
for i in range(n-1):
	t += a[i]
	ans = min(ans,abs(suma-t-t))

print(ans)

Solution (Python):
import math
ans = math.inf
n = int(input())
c = list(map(int, input().split()))
acm = [0]*(n+1)
for i, v in enumerate(c, 1):
    acm[i] += acm[i-1] + v

s, a = 0, acm[n]
for i in range(1, n):
    s = acm[i]
    ans = min(ans, abs((a-s)-s))

print(ans)

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

for i in range(1,n):
    l[i] = l[i-1] + a[i]
sum = sum(a)
ans = 10**10+1
for i in range(len(l)-1):
    x = l[i]
    y = sum - l[i]
    tmp = abs(x-y)
    ans = min(ans,tmp)

print(ans)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = list(accumulate(a))
ans = inf
for i in range(n-1):
    ans = min(ans, abs(b[i]-(b[n-1]-b[i])))
print(ans)

Solution (Python):

n, *a = map(int, open(0).read().split())
s = sum(a)
ans = 10**18
c = 0
for i in range(n - 1):
    c += a[i]
    ans = min(ans, abs(2 * c - s))
print(ans)

Solution (Python):
from itertools import accumulate

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

Solution (Python):
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a))
c = [abs(y * 2 - b[-1]) for y in b][:-1]
print(min([abs(y * 2 - b[-1]) for y in b][:-1]))

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

Solution (Python):
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    total = sum(A)
    ans = INF
    s = 0
    for i in range(N-1):
        s += A[i]
        if ans > abs(total - 2 * s):
            ans = abs(total - 2 * s)

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    total = sum(A)
    ans = INF
    s = 0
    for a in A[:-1]:
        s += a
        if ans > abs(total - 2 * s):
            ans = abs(total - 2 * s)

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    csum = [0]
    csum.extend(accumulate(A))

    ans = INF
    for i in range(1, N):
        tmp = abs(csum[i] - (csum[N] - csum[i]))
        if ans > tmp:
            ans = tmp

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
n=int(input())
a=list(map(int,sys.stdin.readline().strip().split()))
snk=a[0]
rac=sum(a[1:])

s=sum(list(map(abs,a)))
for i in range(1,n-1):
 snk+=a[i]
 rac-=a[i]
 s=min(s,abs(snk-rac))

print(s)

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

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

for i in range(1,n):
    l[i] = l[i-1] + a[i]
sum = sum(a)
ans = 10**10+1
for i in range(len(l)-1):
    x = l[i]
    y = sum - l[i]
    tmp = abs(x-y)
    ans = min(ans,tmp)

print(ans)

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

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


s_list=[0]
sum=0
for i in a_list:
    sum+=i
    s_list.append(sum)



target=s_list[-1]//2

tmp1=10**10
for i in range(1,N):
    tmp2=abs(target-s_list[i])
    tmp1=min(tmp1,tmp2)
    if tmp1 == tmp2:
        ans_index=i


print(abs(s_list[-1]-2*s_list[ans_index]))

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
a_c = a.cumsum()
a_t = a_c[-1]
diff = np.abs(2 * a_c - a_t)
ans = diff[:-1].min()
print(ans)

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

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

res = 10**10
for i in range(N-1):
    res = min(abs(l[i]-r[i+1]), res)

print(res)

Solution (Python):






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





ans = (10**9)*N
x = 0
y = sum(a)
for i in range(N-1):
    x += a[i]
    y -= a[i]
    ans = min(ans,abs(x-y))
    if ans < 2:
        break
print(ans)

Solution (Python):
INF = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
res = INF
t = sum(A)
s = 0
for a in A[:-1]:
    s += a
    res = min(res, abs(t - s - s))
print(res)

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

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

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

sum_a = sum(a)
s = 0
res = float('inf')
for v in a[:-1]:
    s += v
    res = min(res, abs(sum_a - 2 * s))

print(res)

Solution (Python):
from itertools import accumulate

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

b = list(accumulate(a))
ma = b[-1]
mi = 10**10
for sunuke in b[:N-1]:
    arai = ma - sunuke
    if abs(sunuke - arai) < mi:
        mi = abs(sunuke - arai)
print(mi)

Solution (Python):
from itertools import accumulate

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

b = list(accumulate(a))
ma = b[-1]
mi = 10**10
for sunuke in b[:N-1]:
    arai = ma - sunuke
    if abs(sunuke - arai) < mi:
        mi = abs(sunuke - arai)
print(mi)

Solution (Python):
def main():
    N = int(input())
    *A, = map(int, input().split())

    def accumulate(a):
        s = 0
        for x in a:
            s += x
            yield s

    *acc, = accumulate(A)
    acc.pop()

    tot = sum(A)

    ans = -1
    for x in acc:
        if ans > (abs_ := abs(tot - x - x)) or not (~ans):
            ans = abs_

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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

lst = [0]*(N-1)
x = [a[0]]*(N-1)
y = [sum(a)-a[0]]*(N-1)
lst[0] = abs(x[0]-y[0])

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

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

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

S = sum(A)
k = 0
ans = 10**18
for i,a in enumerate(A, start=1):
    k += a
    if N == i:
        break
    ans = min(ans, abs(S - 2*k))
print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = float("INF")
X = sum(a)

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):
N = int(input())
A = list(map(int,input().split()))
S = [0]
for i in range(N):
  temp = S[-1]+A[i]
  S.append(temp)
total = sum(A)
target = total//2
INF = float("inf")
ans = INF

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

Solution (Python):
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n = ini()
a = inl()


def solve():
    al = list(accumulate(a))
    ar = list(reversed(list(accumulate(a[::-1]))))
    ans = 1 << 60
    for i in range(1, n):
        r = abs(al[i - 1] - ar[i])
        ans = min(ans, r)

    return ans


print(solve())

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


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
x = sum(A)
y = 0
z = []

for n in range(N-1):
  y+=A[n]
  z.append(abs(x-2*y))

print(min(z))

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

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

Solution (Python):
from itertools import accumulate

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

if n == 2:
  print(abs(A[0]-A[1]))
  exit()
  
B = list(accumulate(A))

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

print(ans)

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

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

    print(ans)

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

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

Solution (Python):
n = int(input())
a_list = [int(x) for x in input().split()]
temp_list = [0] * n
temp_list[0] = a_list[0]
for i in range(1, n):
    temp_list[i] = a_list[i] + temp_list[i - 1]
ans = 10 ** 15
for i in range(n - 1):
    temp = abs(temp_list[-1] - (temp_list[i] << 1))
    if temp < ans:
        ans = temp
print(ans)

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

A_=[]
a_=0
for a in A:
    a_+=a
    A_.append(a_)

Z=A_[-1]
ans=10**20
for a_ in A_[:-1]:
    if ans > abs(Z-2*a_):
        ans = abs(Z-2*a_)
print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    sm = sum(a)
    xd = 0
    ans = float('inf')
    for i in range(n-1):
        xd += a[i]
        sm -= a[i]
        ans = min(ans, abs(xd - sm))
    print(ans)

        
    
t = 1

for case in range(1,t+1):
    ans = solve()


"""

7
3 1
4 1
5 9
2 6
5 3
5 8
9 7 5

"""

Solution (Python):
import numpy as np


def main():
    n = int(input())
    As = list(map(int, input().split()))
    cumsum = np.cumsum(As)
    ans = float("inf")
    for i in range(n-1):
        ans = min(ans, abs(cumsum[n-1]-2*cumsum[i]))
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
from collections import deque
n = int(input())
a = deque(list(map(int, input().split())))
ans = float('inf')
total = sum(a)
sm = 0
while len(a)>1:
    sm += a.pop()
    ans = min(abs(2*sm-total), ans)
print(ans)

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

Solution (Python):


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

    INF = 1 << 60
    a_sum = [0] * (N + 1)
    for i in range(N):
        a_sum[i + 1] = a_sum[i] + a[i]
    ans = INF
    for i in range(1,N):
        ans = min(ans, abs(a_sum[i] - (a_sum[N] - a_sum[i])))
    print(ans)


if __name__ == "__main__":
    main()

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

H = numpy.cumsum(a)[:-1]
S = sum(a) - H
print(min(abs(H - S)))

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

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

for i in a[:-1]:
    x += i
    ans.append(abs(suma - x * 2))
else:
    print(min(ans))

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

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

for i in range(n - 1):
    x += a[i]
    ans.append(abs(suma - x * 2))
else:
    print(min(ans))

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

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

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

Solution (Python):
from itertools import accumulate

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



total = sum(a_li)
acc = list(accumulate(a_li))
ans = 10 ** 18
for i in range(N - 1):
    ans = min(ans, abs(acc[i] * 2 - total))
print(ans)

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

snk = A[0]
arg = sum(A)-snk
ans = abs(arg-snk)
for i in range(1, N-1):
  snk += A[i]
  arg -= A[i]
  dif = abs(arg-snk)
  ans = min(ans, dif)
print(ans)

Solution (Python):
import itertools
def main():
    n=int(input())
    A=[int(i) for i in input().split()]
    rui = list(itertools.accumulate(A))
    mi = 300000000000
    ind = n-1

    for i in range(n-1):
        mi=min(abs(rui[i]-(rui[ind]-rui[i])),mi)

    print(mi)

if __name__ == '__main__':
    main()

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

s = sum(a)
x = a[0]
res = abs(s - 2 * x)
for i in range(1, N - 1):
    x += a[i]
    y = s - x
    if res > abs(y - x):
        res = abs(y - x)
print(res)

Solution (Python):
def INT():
    return int(input())

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

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

N = INT()
a = LI()

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

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


left = a[0]
right = sum(a[1:])
ans = abs(left - right)
for i in range(1, n-1):
    left += a[i]
    right -= a[i]
    ans = min(ans, abs(left-right))
print(ans)

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

x=sum(A)
y=0
ans=10**16

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

print(ans)

Solution (Python):
import itertools

n = int(input())
lis = list(map(int, input().split()))
k = list(itertools.accumulate(lis))
x = sum(lis)

ans = 100100100100100100

for i in range(n-1):
    t = k[i]
    t2 = x - t
    
    ans = min(ans, abs(t-t2))

print(ans)

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

for i in range(1,n):
    l[i] = l[i-1] + a[i]
sum = sum(a)
ans = 10**10+1
for i in range(len(l)-1):
    x = l[i]
    y = sum - l[i]
    tmp = abs(x-y)
    ans = min(ans,tmp)

print(ans)

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

sm = []
tmp = 0
for a in As:
  tmp += a
  sm.append(tmp)
  
rlt = sum(map(abs, As))
for i in range(N-1):
  rlt = min(rlt, abs(2*sm[i]-sm[-1]))
  
print(rlt)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
summ = sum(a)
ruisekiwa = []
tmp = 0
for i in range(n):
    tmp += a[i]
    ruisekiwa.append(tmp)
ans = 100100100100
for i in range(len(ruisekiwa) - 1):
    ans = min(ans, abs(ruisekiwa[i] - (summ - ruisekiwa[i])))
print(ans)

Solution (Python):
import sys
import itertools

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = rl()
s = sum(a)
t = list(itertools.accumulate(a))
min_ = inf
for i in range(n-1):
    x = t[i]
    min_ = min(min_, abs((s-x) - x))
print(min_)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
nums=sum(a)-a[0]
numa=a[0]
def ab(num1,num2):
    return abs(num1-num2)
ans=ab(nums,numa)
for i in range(n-2):
    nums-=a[i+1]
    numa+=a[i+1]
    ans=min(ans,ab(nums,numa))
print(ans)