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)
accu = 0
mi = 10**10
for i in a[:-1]:
    accu += i
    diff = abs(2*accu - s)
    mi = min(mi, diff)
print(mi)

Solution (Python):
import itertools
n = input()
m = list(map(int, input().split()))
s = sum(m)
f = lambda x: abs(x-(s-x))
ans = f(m[0])
for i in list(itertools.accumulate(m))[1:-2]:
    ans = min(ans, f(i))
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    S = [0 for i in range(N+1)]
    for i in range(1, N+1):
        S[i] = S[i-1] + A[i-1]

    mi = 10**10
    for i in range(1, N):
        S1 = S[i] - S[0]
        S2 = S[N] - S[i]
        d = abs(S1-S2)
        
        if d < mi:
            mi = d
            
    print(mi)
        
if __name__ == "__main__":
    main()

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
d = sum(a)
snuke = 0
arai = 0
ans = 10000000000
for i in range(n-1):
    snuke += a[i]
    arai = d - snuke
    ans = min(ans,abs(snuke-arai))
print(ans)

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

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

sum_a=0
slist=[]
for a in alist:
  sum_a+=a
  slist.append(sum_a)


allsum=slist[-1]
answer=float("inf")
for i in range(N-1):
  score_a=slist[i]
  score_b=allsum-score_a
  
  cand=abs(score_a-score_b)
  
  answer=min(answer,cand)
  
print(answer)

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

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

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

for i in range(n):
    sum+=a[i]
    s[i]=sum
min = 2000000000
for i in range(n-1):
    d=abs(s[i]*2-s[n-1])
    if d < min:
        min =d
print(min)

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
forward = []
backward = []
sumA = 0
for i in range(N):
    forward.append(A[i]+sumA)
    sumA += A[i]
sumA = 0
for j in range(N):
    backward.append(A[N-j-1]+sumA)
    sumA += A[N-j-1]
sa = []
for i in range(N-1):
    sa.append(abs(forward[i]-backward[N-i-2]))

print(min(sa))

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

d = sum(a)
ans = float('inf')
for i in range(n-1):
    if i == 0:
        x = a[0]
        y = d - x
    else:
        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()))

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

print(res)

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

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

sleft = []
sright = [0]*n
left = 0
right = 0
for i in range(n):
    left += a[i]
    sleft.append(left)
for i in range(n-1,-1,-1):
    right += a[i]
    sright[i] = right
ans = float('inf')
for i in range(1,n):
    ans = min(ans, abs(sright[i] - sleft[i-1]))
print(ans)

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

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

ans = int(1e20)
for i in range(N-1):
    ans = min(ans, abs(sa[i] - (sa[-1] - sa[i])))
print(ans)

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

Max = N[-1]
ans = float("INF")
for i in range(1, n):
    if abs(N[i] - (Max-N[i])) < ans:
        ans =  abs(N[i] - (Max-N[i]))
print(ans)

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

cumulative_sum = []
cnt = 0
for i in range(n):
    cnt += a[i]
    cumulative_sum.append(cnt)

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

print(ans)

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

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

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

print(ans)

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

ans = float('inf')
for i in range(1,N):
    sunke = S[i] - S[0]
    araiguma = S[-1] - S[i]
    ans = min(ans, abs(sunke - araiguma))

print(ans)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
INF = 10**18
ans = INF
X = 0
for a in A[:-1]:
    X += a
    ans = min(ans, abs(2*X-sum_A))
print(ans)

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

n = int(input())
a = list(map(int, input().split()))
cum_sum = [0]*n

total = 0
for i in range(n):
    total += a[i]
    cum_sum[i] = total

max_sum = cum_sum[-1]

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

print(ans)

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

Solution (Python):
from itertools import accumulate
N = int(input())
an = list(map(int, input().split()))
res = [0] + an
res = list(accumulate(res))
ans = 10e+9
for i in range(1, N):
    ans = min(ans, abs(res[i] - (res[-1]-res[i])))
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-1):
    x += a[i]
    y -= a[i]
    if ans > abs(x-y):
        ans = abs(x-y)
print(ans)

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

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=1000000000000000
for i in range(N-1):
    S=S-a[i]
    SS=SS+a[i]
    if mi>=abs(S-SS):
        mi=abs(S-SS)
print(mi)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
S = sum(a)
sum =[0]*n
sum[0] = a[0]
su =0
ar =0

min = 10**20

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

print(min)

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


if __name__ == '__main__':
    main()

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

s = [0]*(n-1)
s[0] = a[0]
A = sum(a)
ans = 1e100
for i in range(n-2):
  s[i+1] = s[i] + a[i+1]

for t in s:
  ans = min(ans, abs(2*t - A))
print(ans)

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

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

n = ni()
a = na()

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

ans = 100000000000000

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

print(ans)

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

t = sum (a)
ans = 10 ** 10 + 1
X = 0
for i, x in enumerate(a):
    X += x
    Y = t - X
    ans = min(ans, abs(X-Y))
    if i+ 1 == n -1:
        break

print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
Min = np.inf
s = 0
for i in range(len(a)-1):
    s += a[i]
    Min = min(Min, abs(2 * s- total))
print(Min)

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    minabs = float("inf")
    tmpx = 0
    tmpy = sum(A)
    for i in range(N-1):
        tmpx += A[i]
        tmpy -= A[i]
        if abs(tmpx - tmpy) < minabs:
            minabs = abs(tmpx - tmpy)
    print(minabs)

if '__main__' == __name__:
    resolve()

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
a = li[0]
s = sum(li)
b = s - a
ans_li = [abs(a-b)]


for i,l in enumerate(li):
    if i == 0:
        continue
    if i == n-1:
        continue
    a+=l
    b-=l
    ans_li.append(abs(a-b))
print(min(ans_li))

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]

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

Solution (Python):
import numpy as np

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

A = np.asarray(A)
A_cumsum = A.cumsum()
total = A.sum()
diff = np.abs(2*A_cumsum - total)
ans = min(diff[:-1])
print(ans)

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

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

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

print(ans)

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

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

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

def main():
    N = int(input())
    A = list(map(int, readline().rstrip().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)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = [None] * (N-1)
ans[0] = sum(a[1:]) - a[0]
mina = abs(ans[0])

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

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

for i in range(1,n-1):
    k=k+a[i]
    if abs(t-2*k) < mi:
        mi=abs(t-2*k)
print(mi)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
X=sum(A)
x=0
ans=2100000007
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())
li = list(map(int,input().split()))
ans = 10000000000000
x = 0
y = sum(li)

for i in range(0,n-1):
    x += li[i]
    y -= li[i]
    z = abs(x-y)
    if z < ans:
        ans = z

print(ans)

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

for i in range(N):
	sum+=a[i]
for i in range(N-1):
	ans+=a[i]
	arai=sum-ans
	mini=min(mini,float(abs(ans-arai)))

print(int(mini))

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

for i in range(N):
	sum+=a[i]
for i in range(N-1):
	ans+=a[i]
	arai=sum-ans
	mini=min(mini,float(abs(ans-arai)))

print(int(mini))

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

x, y = 0, sum(a)
ans = abs(a[0] - (sum(a) - a[0]))
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 = 10**50
x, y = 0, sum(A)
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()))
for i in range(N-1):
    A[i+1] = 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)

Solution (Python):

import sys
import numpy as np

readline = sys.stdin.readline

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

    base0 = A[0]
    base1 = sum(A) - base0

    ans = abs(base1 - base0)

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

    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
from itertools import accumulate
def main():
  N = int(input())
  A = [int(_) for _ in input().split()]
  B = list(accumulate(A))
  s = B[-1]
  B = [abs(2 * b - s) for b in B]
  print(min(B[:-1]))
  return

if __name__ == '__main__':
  main()

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    total = sum(a)
    ans = []
    x = 0
    for i in range(n - 1):
        x += a[i]
        y = total - x

        ans.append(abs(x - y))

    print(min(ans))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
mn_list = []
sunuke = a[0]
araiguma = sum(a[1:])
res = abs(sunuke-araiguma)
for i in range(1,n-1):
    sunuke += a[i]
    araiguma -= a[i]
    res = min(res,abs(sunuke-araiguma))
print(res)

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

Solution (Python):
import itertools
n=int(input())
a=list(map(int,input().split()))
li=list(itertools.accumulate(a))
ans=float("inf")


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

print(ans)

Solution (Python):
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
b=a.cumsum()
ans=float("inf")
for i in range(n-1):
    ans=min(ans,abs(b[-1]-b[i]-b[i]))
print(ans)

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

Solution (Python):
import itertools
def slove(n, a):
    total = sum(a)
    ans = min(map(lambda x: abs(total - x*2), itertools.accumulate(a[:-1])))
    return ans

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(slove(n, a_list))

Solution (Python):
n = int(input())
num_list = list(map(int,input().split()))
sum_cnt = sum(num_list)
sunuke = 0
arai = 0
tmp = 0
tmp_list = []
for i in range(len(num_list)-1):
    if i == 0:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
        tmp_list.append(tmp)
    else:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
        tmp_list.append(tmp)
print(min(tmp_list))

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):
def main():
    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-1):
        x+=a[i]
        y-=a[i]
        ans=min(abs(x-y),ans)
    print(ans)
if __name__=="__main__":
    main()

Solution (Python):
n=int(input())
sa=[]
a=list(map(int,input().split()))
s=0
for ai in a:
  s+=ai
  sa.append(s)

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

Solution (Python):
n, *A = map(int, open(0).read().split())
x, y = A[0], 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()))
sum_a = sum(a)
sunuke = a[0]
mini = abs(sum_a - 2*sunuke)
for i in range(1,N-1):
    sunuke += a[i]
    mini = min(mini,abs(sum_a - 2*sunuke))

print(mini)

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

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

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

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

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

sm = sum(A)
x = 0
y = sm
ans = 1001001001001001001

for idx, a in enumerate(A):
  if idx == n - 1:
    break
  
  x  = x + a
  y = y - a
  
  ans = min(ans, abs(x - y))
print(ans)

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

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

Solution (Python):


N=int(input())

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

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

print(ans)

Solution (Python):
import numpy as np

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

cum_sum = np.cumsum(a)
track_min = float('inf')

for i in range(n-1):
    x = int(cum_sum[i])
    y = int(cum_sum[-1]-cum_sum[i])
    diff = abs(x-y)
    if diff<track_min:
        track_min = diff
    
print(track_min)

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    for i in range(n - 1): a[i+1] += a[i]
    res = float('inf')
    for i in range(n - 1): res = min(res, abs(a[-1] - a[i] * 2))
    print(res)

if __name__ ==  '__main__':
    main()

Solution (Python):
from itertools import accumulate
n = int(input())
l = list(map(int,input().split()))
s = sum(l)
l1 = list(accumulate(l))
del l1[-1]
l2 = [abs(2*i-s) for i in l1]
print(min(l2))

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

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    n = int(input())
    cards = list(map(int,input().split()))
    ruisekiwa = [0] + [0] * n

    for i in range(0,n):
        ruisekiwa[i+1] = ruisekiwa[i] + cards[i]
    
    
    mn = 100000000000000000000000000
    for sunuke_take in range(1,n):
        
        araiguma_take = n - sunuke_take
        sunuke_sum = ruisekiwa[sunuke_take] - ruisekiwa[0]
        araiguma_sum = ruisekiwa[n] - ruisekiwa[sunuke_take]
        mn = min(mn,abs(sunuke_sum-araiguma_sum))
        
        
    print(mn)




if __name__ == '__main__':
    main()

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

f_inf = float("inf")
res = f_inf
for i in range(n - 1):
    arai += A[i]
    sunuke -= A[i]
    res = min(res, abs(sunuke - arai))
print(res)

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

x = [0 for i in range(n-1)]
y = [0 for i in range(n-1)]
num = sum(lst)
x[0] = lst[0]
y[0] = num-lst[0]

for i in range(1,n-1):
    x[i] = x[i-1]+lst[i]
    y[i] = num-x[i]



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

print(ans)

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

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  l = 0
  r = sum(A)
  LIST = []
  for i in range(n-1):
    l += A[i]
    r -= A[i]
    LIST.append(abs(l-r))
  print(min(LIST))
  
if __name__ == '__main__':
  main()

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

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 10**10
    


    
    for i in range(N-1):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)


        if min_val > val:
            min_val = val


    return min_val

print(main(a_arr))

Solution (Python):
import numpy as np

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

suml = np.cumsum(a)
sumr = np.cumsum(a[::-1])[::-1]
diff = np.abs(sumr[1:] - suml[:-1])

print(min(diff))

Solution (Python):
n = int(input())
ns = list(map(int, input().split()))
min_x = float('inf')
sum_x = 0
total_sum = sum(ns)
for i in range(n-1):
    sum_x += ns[i]
    min_x = min(min_x, abs(total_sum-2*sum_x))
print(min_x)

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

sub = sum(a)
s = 0
ans = (10 ** 10) + 100
for i in range(n):
    s += a[i]
    if (i + 1) < n:
        ans = min(ans, abs(sub - (2 * s)))

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
max_ans = sum(a)
ans = abs(a[0]-(max_ans - a[0]))
sumu = a[0]
for i in range(1,n-1):
  sumu += a[i]
  arai = max_ans - sumu
  kari = abs(sumu-arai)
  if kari < ans:
    ans = kari
print(ans)

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

sum_ls = list(np.cumsum(a_ls))
sum_ls.insert(0,0)

ans = float('inf')
for i in range(1,n):
    su = sum_ls[i]
    ara = sum_ls[-1] - sum_ls[i]
    dif = abs(su-ara)
    if dif < ans:
        ans = dif

print(ans)

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

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

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

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a[1:])
a = a[1:-1]
ans = abs(x - y)


for i in range(n - 2):
    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 = []
sunuke = 0
Sum = sum(a)
for i in range(n-1):
    sunuke += a[i]
    ans.append(abs(Sum-2*sunuke))
print(min(ans))

Solution (Python):
import math






N = int(input())
ARR = [int(s) for s in input().split(" ")]
def calculate(n,arr):
    lSum = 0
    tSum = sum(arr)
    res = []
    for index in range(n-1):
        ar = arr[index]
        lSum = lSum + ar
        rSum = tSum - lSum
        res.append(int(math.fabs(lSum-rSum)))

    print(min(res))



calculate(N,ARR)

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

Solution (Python):


N=int(input())

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


B=[]

for i in A:
    if len(B)==0:
        B.append(i)
    else:
        B.append(B[-1]+i)
        

C=[0 for i in range(N)]

for i in range(N):
    C[i]=abs(B[N-1]-2*B[i])
print(min(C[:N-1]))

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

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

Solution (Python):
n = int(input().strip())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(0, (n - 1)):
    s.append(s[i] + a[i + 1])
mi = float('inf')
su = sum(a)
for i in range(n - 1):
    rep = abs(su - 2 * s[i])
    if rep < mi:
        mi = rep
print(mi)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
sm = sum(a)//2
mn = 10**10
ar = a[0]
su = a[-1]
for i in range(1,len(a)-1):
    if abs(sm - ar) < mn:
        mn = abs(sm - ar)
        mn_i = i
    ar += a[i]

if len(a) > 2:
    ar = sum(a[0:mn_i])
    su = sum(a[mn_i::])
    print(abs(ar-su))
else:
    print(abs(ar-su))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sunuke = a[0]
arai = sum(a[1:])
result = abs(sunuke-arai)
for el in a[1:-1]:
    sunuke += el
    arai -= el
    if abs(sunuke-arai) < result:
        result = abs(sunuke-arai)
print(result)

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

S = A[0]
T = sum(A) - S
cnt = abs(S - T)
for i in range(1, N - 1):
    S += A[i]
    T -= A[i]
    cnt = min(cnt, abs(S - T))
print(cnt)

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

snuke = cards[0]
araiguma = sum_cards - cards[0]

ans = abs(snuke - araiguma)

for num in cards[1:n-1]:
    snuke += num
    araiguma -= num
    ans = min(ans, abs(snuke-araiguma))

print(ans)