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()))
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):
import numpy as np
n = int(input())
a = list(map(int, input().split()))

S = sum(a)
s = np.cumsum(a)
ans = float('INF')

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

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from itertools import accumulate
s=list(accumulate(a))
a_sum=sum(a)
ans=10**18
if n==2:
  print(abs(a[0]-a[1]))
  exit(0)
for i in range(1,n-1):
  x=s[i]
  y=a_sum-x
  ans=min(ans,abs(x-y))
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))[::-1]

    snuke = sum(A)
    arai = 0

    res = f_inf
    for i in range(n - 1):
        snuke -= A[i]
        arai += A[i]
        res = min(res, abs(snuke - arai))

    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
A = nl()


def solve():
    tot = sum(A)
    ans = 1 << 60
    s = 0
    for i, x in enumerate(A):
        if i == N - 1:
            break
        s += x
        a = abs(2 * s - tot)
        ans = min(ans, a)
    return ans


print(solve())

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

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



sa=sum(a)
ans=10**10+1
x=0
for i in range(0,n-1):
  x+=a[i]
  if abs(2*x-sa)<ans:
    ans=abs(2*x-sa)
print(ans)

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

X = sum(A)
Y = 0
MIN = 10**18
for i,a in enumerate(A):
    if i < N-1:
        X -= a
        Y += a
        tmp = abs(X-Y)
        if tmp < MIN:
            MIN = tmp
    
print(MIN)

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
Acum = list(accumulate(A))

ans = 10 ** 20

for a in Acum[:-1]:
    snuke = a
    arai = Acum[-1] - a
    ans = min(ans, abs(snuke - arai))
print(ans)

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

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

Solution (Python):
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
sa=0
sb=sum(a)
ans=float("inf")
for i in range(n-1):
    sa+=a[i]
    sb-=a[i]
    ans=min(ans,abs(sa-sb))
print(ans)

Solution (Python):

n = int(input())
arr = list(map(int, input().split()))
ruiseki = [0] * (n + 1)
for i in range(1, n + 1):
    ruiseki[i] = ruiseki[i - 1] + arr[i - 1]
ans = 10**10
for i in range(1, n):
    takahashi = ruiseki[i]
    raskal = ruiseki[n] - takahashi
    ans = min(ans, abs(raskal - takahashi))
print(ans)

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

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

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

s = sum(A)

x = 0
ans = 1 << 60
for a in A[:-1]:
    x += a
    ans = min(ans, abs(s - 2 * x))

print(ans)

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

min_diff = float('inf')
a_sum = sum(a)
l_sum = 0

for i in range(N - 1):
  l_sum += a[i]
  min_diff = min(min_diff, abs(l_sum * 2 - a_sum))

print(min_diff)

Solution (Python):
N = int(input())
*a, = map(int, input().split())
l, r = 0, sum(a)
ans = 10**19
for i in range(N-1):
    l += a[i]
    r -= a[i]
    t = l-r
    if abs(t) < ans:
        ans = abs(t)
print(ans)

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

print(min(d))

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

if __name__ == '__main__':
    main()

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
z=list(accumulate(lis))

mn=inf
for i in range(n-1):
    dif=abs(z[-1]/2-z[i])
    if dif<mn:
        mn=dif
print(int(2*mn))

Solution (Python):
N = int(input())
L = list(map(int, input().split()))
total = sum(L)






sunuke = 0
ans = 2**64-1
for i in range(N-1):
  sunuke += L[i]
  racoon = total - sunuke
  ans = min(ans, abs(sunuke - racoon))
print(ans)

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

Solution (Python):
def main():
    input()
    t = list(map(int, input().split()))
    
    
    
    all = sum(t)
    left = t[0]
    right = all - t[0]
    ans = abs(left-right)
    for i in range(1, len(t)-1):
        left += t[i]
        if ans > abs(left-(all-left)):
            ans = abs(left-(all-left))
    print(ans)


if __name__ == '__main__':
    main()

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

s = 0
for i in a:
    s += i

ans = float('inf')
tmp = 0
for i in range(n-1):
    tmp += a[i]
    ans = min(ans,abs(s-tmp-tmp)) 

print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    cumsum = A
    for i in range(1, N):
        cumsum[i] += cumsum[i - 1]
    ans = 10 ** 15
    for i in range(N - 1):
        ans = min([ans, abs(cumsum[i] - (cumsum[-1] - cumsum[i]))])
    print(ans)


if __name__ == '__main__':
    main()

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

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

sal=sum(al)
res=10**9+1
temp=0
for i in range(0,n-1):
    temp += al[i]
    res = min(res,abs(sal/2-temp))
    if res <=0.5:
        break

print(int(res*2))

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

res = 10**12
n = sum(a)
x = 0
for i in range(N-1):
    x += a[i]
    y = n - x
    ans = abs(x-y)
    res = min(res,ans)
print(res)

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

a = abs(2*np.cumsum(a) - a.sum())[:-1]

print(min(a))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ruisekiwa = [0]*(N+1)
now = 0
minimum = 10**10
for i in range(N):
  now += A[i]
  ruisekiwa[i+1] = now
for i in range(N-1):
  snuke = ruisekiwa[i+1]
  arai = ruisekiwa[N]-snuke
  K = abs(snuke-arai)
  if K < minimum:
    minimum = K
print(minimum)

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

ans = 2*10**9
allsum = sum(a)
snukesum = 0

for n in range(1,N):
  snukesum += a[n-1]
  ans_candidate = abs(2*snukesum- allsum)
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)

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

min=1000000000000000
left_sum=0
right_sum=sum(a)
for i in range(n-1):
    left_sum += a[i]
    right_sum -= a[i]
    xy=abs(left_sum-right_sum)
    if xy < min:
        min=xy
print(min)

Solution (Python):
n = int(input())
L = list(map(int, input().split()))
M = sum(L)
m = float('inf')
s = 0
for i in range(n - 1):
    s += L[i]
    r = M - s
    m = min(m, abs(s - r))
print(m)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
import numpy as np

n = ii()
A = iil()

l = np.cumsum(A)
su = l[-1]

ans = 1e18
for i in range(n-1):
    x = l[i]
    y = su - x
    ans = min(ans,abs(x-y))

print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
total = sum(A)
x = 0
ans = float("inf")

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

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
sum_A = np.sum(A)
cumsum_A = np.cumsum(A)

ans = float('inf')
for i in range(N - 1):
    ans = min(ans, abs(sum_A - 2 * cumsum_A[i]))
print(ans)

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

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

whole = sum(a)

if n == 2:
    print(abs(a[0] - a[1]))
else:
    now = 0
    ans = float("inf")
    for i in a[:-1]:
        now += i
        diff = abs(whole - 2 * now)
        ans = min(ans, diff)

    print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1





N = I()
A = IL()

if N==2:
  PE(abs(A[0]-A[1]))
  

S = [A[0]]
for a in A[1:]:
  S.append(S[-1]+a)
SUM = S[-1]
S = [ abs(SUM-s-s)for s in S[1:N-1]]
P(min(S))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ruiseki = [0]*(N+1)
total = 0
now = 10**20
sa = 0
now_2 = 0
for i in range(N):
  total += A[i]
  ruiseki[i+1] = total
for i in range(1,len(ruiseki)-1):
  snuke = ruiseki[i]-ruiseki[0]
  arai = ruiseki[N]-ruiseki[i]
  now_2 = abs(snuke-arai)
  now = min(now,now_2)
print(now)

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

a2 = [0]
for i in a:a2.append(a2[-1]+i)

total_sum = a2[-1]

a2.pop(0)
sum_n = a2[-1]

output = []
for i in range(N-1):
    output.append(abs(sum_n - (2 * a2[i])))
    
print(min(output))

Solution (Python):

import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)
def inputintlist():
    return list(map(int,input().split()))


n=int(input())
A=inputintlist()
ssum=sum(A)
ans=inf
now=0
for a in A[:-1]:
    now+=a
    x=now
    y=ssum-now
    ans=min(ans,abs(x-y))
    

print(ans)

Solution (Python):

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

Sum = 0
Min = float("inf")
SumArray = [0] * N
for i in range(N):
    Sum += a[i]
    SumArray[i] = Sum

if N == 2:
    print(abs(a[0] - a[1]))
else:
    for i in range(N-1):
        temp = abs(SumArray[i] - (SumArray[N-1] - SumArray[i]))
        if temp < Min:
            Min = temp

    print(int(Min))

Solution (Python):
n = int(input());
a = input().split(" ");
x = int(a[0]);
y = 0;
for i in range(1,n) :
	y += int(a[i]);

ans = abs(x - y);
for i in range(1,n-1) :
	x += int(a[i]);
	y -= int(a[i]);
	if abs(x - y) < ans :
		ans = abs(x - y);
print(ans);

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

sum_a = sum(A)
cum_a = [0]*n
cum_a[0] = A[0]

ans = abs(sum_a-2*cum_a[0])

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

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

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

cum = [0]

for a in A:
    s = a + cum[-1]
    cum.append(s)

ans = None

for s in cum[1:-1]:
    x = s
    y = cum[-1] - s
    if ans is None:
        ans = abs(x - y)
    else:
        ans = min(ans, abs(x - y))

print(ans)

Solution (Python):
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

a_sum = sum(a)
tmp = 0
ans = INF

for i in range(N-1):
	tmp += a[i]
	diff = abs(a_sum - tmp - tmp)
	ans = min(ans, diff)

print(ans)

Solution (Python):
from itertools import accumulate
input()
A = list(accumulate([int(i) for i in input().split()]))
ans = 99 ** 9
for a in A[:-1]:
    ans = min(ans,abs(A[-1]-a-a))
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 = 10 ** 10
for i in range(1, n):
    x = cumsum[i]
    y = cumsum[n] - x
    ans = min(ans, abs(x - y))

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
asum = [0]*n
for i in range(n):
  asum[i] = asum[i-1] + a[i]
total = asum[-1]
half = total/2
ans = abs(asum[0]-half)*2
for j in range(0,n-1):
  s = abs(asum[j]-half)*2
  if s < ans:
    ans = s
print(int(ans))

Solution (Python):
import collections


def main():
    n = int(input())
    a = input_list()
    sum_a = sum(a)
    wa = []
    for i, v in enumerate(a):
        if i == 0:
            wa.append(v)
        else:
            wa.append(v+wa[i-1])
    ans = float('inf')
    for i in range(n-1):
        ans = min(ans, abs(sum_a-(wa[i]*2)))
    print(ans)


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


if __name__ == '__main__':
    main()

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

partial_sum = [0] * N

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

ans = abs(partial_sum[0]-(partial_sum[-1]-partial_sum[0]))

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

print(ans)

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

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

ans = 10e+12
for i in range(1, n):
  ans = min(ans, abs(l[i] - r[i]))
print(ans)

Solution (Python):
from itertools import*;input();*a,s=accumulate(map(int,input().split()));print(min(abs(s-x*2)for x in a))

Solution (Python):
from itertools import*;*a,s=list(accumulate(map(int,open(0).read().split()[1:])));print(min(abs(s-x*2)for x in a))

Solution (Python):
from itertools import*;*a,s=list(accumulate(map(int,open(0).read().split()[1:])));print(min(abs(s-x*2)for x in a))

Solution (Python):
from itertools import*
_, *d = map(int, open(0).read().split())
*a, s = list(accumulate(d))
print(min(abs(s - x*2) for x in a))

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   accum = [A[0]]
   total = sum(A)
   ans = []
   for i in range(1,N):
      accum.append(accum[i-1] + A[i])
   accum.pop()
   
   for x in accum:
      y = total - x
      ans.append(abs(x - y))
      

   return min(ans)

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

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

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


if n == 2:
    print(abs(a[0]-a[1]))
else:
    goukei = sum(a)
    x = [0]*n
    x[0] = a[0]
    ans = 10**11
    for i in range(1, n-1):
        x[i] = x[i-1] + a[i]
        y = goukei - x[i]
        ans = min(ans, abs(x[i]-y))
    print(ans)

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

all_sum = sum(li)
x = 0
y = all_sum
ans = 10**18

for i in range(n):
    x += li[i]
    y -= li[i]

    if ans >= abs(x-y):
        ans = abs(x-y)

    if i == n - 2:
        break

print(ans)

Solution (Python):
def resolve():
	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]
	ans = float('inf')
	for i in range(1, n):
		ans = min(ans, abs(s[-1] - s[i]*2))
	print(ans)
resolve()

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

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
ans = pow(10, 15)
key = sum(a)
p = 0
for i in range(n-1):
  p += a[i]
  if ans > abs(key-2*p):
    ans = abs(key-2*p)
    
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    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]
    ans=INF
    for i in range(1,N):
        tmp=abs(S[-1]-2*S[i])
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):

"""
Created on Thu May 14 12:49:47 2020

@author: shinba
"""
import itertools

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

b = list(itertools.accumulate(a))

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

Solution (Python):
input()
cards = tuple(map(int, input().split(' ')))

a = sum(cards[1:])
s = cards[0]
diff_min = abs(a - s)

for card in cards[1:-1]:
    a -= card
    s += card
    diff_min = min(diff_min, abs(a - s))

print(diff_min)

Solution (Python):
import itertools
n = int(input())
a = list(itertools.accumulate(list(map(int, input().split()))))
ans = 10000000000000
sum_a = a[-1]
for i in range(n-1):
  ans = min(ans,abs(sum_a - 2 * a[i]))
print(ans)

Solution (Python):

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

print(ans)

Solution (Python):
import sys
from itertools import accumulate

n = int(input())
a = list(accumulate(map(int, sys.stdin.readline().split())))
sa = a.pop()
print(min(abs(sa - 2*i) for i in a))

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

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

ans = float("inf")
for i in range(1, N):
    snuke = S[i] - S[0]
    kuma = S[N] - S[i]
    score = abs(snuke - kuma)
    ans = min(ans, score)

print(ans)

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

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

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

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()))
su = a[0]
ar = sum(a[1:])
p=abs(su-ar)
for i in a[1:-1]:
    su += i
    ar -= i
    p=min(abs(su-ar),p)
print(p)

Solution (Python):
n = int(input())
a = [int(x) for x in 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):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy





sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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




def main():
    n = ni()
    a = na()

    total = sum(a)

    sunuke = 0
    ans = sys.maxsize
    for i in range(n - 1):
        sunuke += a[i]
        ans = min(ans, abs(total - sunuke*2))

    print(ans)

if __name__ == '__main__':
    main()

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):
import numpy as np

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

cumsumA = np.cumsum(arrA)

ans = 10**9 * 2 * 10**5
for num in cumsumA[:-1]:
    ans = min(ans,abs(num*2 - cumsumA[-1]))

print(ans)

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

print(min(ans))

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

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = np.array(readline().split(), np.int64)
    total = A.sum()
    X = A[:-1].cumsum()
    Y = total - X
    ans = np.abs(X-Y).min()
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
s = 0
b = sum(A)
ans = float("inf")
for i, a in enumerate(A):
    s += a
    b -= a
    if i == N - 1:
        break
    ans = min(ans, abs(s - b))
print(ans)

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

if n == 2:
    ans = abs(a[0]-a[1])
else:
    ans = 10**100
for i in range(1,n-1):
    if ans > abs(sum-2*sa[i]):
        ans = abs(sum-2*sa[i])

print(ans)

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

for i in range(N):
    s += a[i]
    csum.append(s)

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

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

print(ans)

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

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

print(ans)

Solution (Python):
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))
sumA = list(accumulate(A))
maxA = sumA[-1]
ans = 10**18

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

print(ans)

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