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):
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    x = 0
    y = sum(a)
    m = 10**100
    for i in range(N-1):
        x += a[i]
        y -= a[i]
        m = min(m, abs(x-y))
    print(m)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
aa=sum(a)-a[0]
tmp=a[0]
t=abs(tmp-aa)
ans=float("inf")
if ans>t:
    ans=t
for i in range(1,n-1):
    tmp+=a[i]
    aa-=a[i]
    t=abs(tmp-aa)
    if ans>t:
        ans=t
print(ans)

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
for i in range(1, n):
  lst[i] += lst[i - 1]
z = lst[-1]
res = 10 ** 20
for i in range(n - 1):
  res = min(res, abs(lst[i] - (z - lst[i])))
print(res)

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from numpy import cumsum
left_cumsum=cumsum(a)
a.reverse()
right_cumsum=cumsum(a)
ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_cumsum[i]-right_cumsum[-i-2]))
print(ans)

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

ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_ruiseki[i]-right_ruiseki[-i-2]))
print(ans)

Solution (Python):
import itertools
def main():
    N = int(input())
    a = list(map(int, input().split()))
    AC = list(itertools.accumulate(a))
    M = sum(a)
    ans = abs(M - a[0]*2)

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


if __name__ == '__main__':
    main()

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

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]

result = 10**10
for i in range(1,n):
  snuke = s[i]
  arai = s[n] - s[i]
  result = min(result, abs(snuke-arai))
print(result)

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

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

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

Solution (Python):
N=int(input())
*A,=map(int,input().split())
S=sum(A)

count=[[]for _ in range(N-1)]
count[0]=[A[0],S-A[0]]
i=1
while i<N-1:
    count[i]=[A[i]+count[i-1][0],S-(A[i]+count[i-1][0])]
    i+=1

print(min(abs(l-r) for l,r in count))

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

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

a = list(map(int,input().split()))
s = sum(a)
l = a[0]
m = abs((s-l)-l)
for i in range(1,N-1):
    l += a[i]
    m = min(m,abs((s-l)-l))
print(m)

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

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

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

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

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

s = sum(a)
t = 0
ans = float("inf")

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

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

y=sum(a)
x=0
mn=10**18
for i in range(n-1):
    x+=a[i]
    y-=a[i]
    mn=min(mn, abs(x-y))

print(mn)

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

Solution (Python):
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
cumsum_a = a.cumsum()
sum_a = cumsum_a[-1]
ans = 2 * 10**9

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

print(ans)

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

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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 power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a1 = [0]
for i in range(n):
    a1.append(a1[-1]+a[i])
def sumArea(l,r):
    return a1[r] - a1[l]

ans = inf
for i in range(1,n):
    ans = min(ans,abs(sumArea(0,i)-sumArea(i,n)))
print(ans)

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

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

from itertools import accumulate
ac = [0] + list(accumulate(A))

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

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0]*(N+1)

    for i in range(1,N+1):
        X[i] += A[i-1] + X[i-1]
    ans  = float('INF') 
    for i in range(1,N):
        ans = min(ans,abs(X[N] - 2*X[i]))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0]*(N+1)

    for i in range(1,N+1):
        X[i] += A[i-1] + X[i-1]
    ans  = float('INF') 
    for i in range(1,N):
        ans = min(ans,abs(X[N] - 2*X[i]))
    print(ans)

if __name__ == '__main__':
    main()

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

ans = 10 ** 15
now = 0
for i in range(N):
  now += A[i]
  if (i != N - 1):
    ans = min(ans, abs(m - 2 * now))

print(ans)

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

sunuke = A_s[0]
kuma = sum(A_s[1:])
mini = abs(sunuke - kuma)


for i in range(1, N - 1):
    sunuke += A_s[i]
    kuma -= A_s[i]
    
    mini = min(mini, abs(sunuke - kuma))

print(mini)

Solution (Python):
N=int(input())
a=input().split()
a=[int(b) for b in a]
numbers=[]
number=0
for a_ in a:
    number+=a_
    numbers.append(number)
del numbers[-1]
if N==2:
    print(abs(a[0]-a[1]))
else:
    whole=sum(a)
    answers=[]
    for number in numbers:
        answer=abs(number*2-whole)
        answers.append(answer)
    print(min(answers))

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

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


INF = 10 ** 15

N = a_int()
A = ints()


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

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

x = a[0]
y = sum(a[1:])
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())
nums = [int(i) for i in input().split()]

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

ans = float('inf')
for i in range(n - 1):
    x = nums[i]
    y = nums[-1] - nums[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]
m=a[-1]
ans=10**18
for i in range(n-1):
  ans=min(ans,abs(m-2*a[i]))
print(ans)

Solution (Python):
import itertools

N = int(input())
A = list(map(int,input().split()))
total = sum(A)
ACC = list(itertools.accumulate(A))

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

print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
ans = float('inf')
sums = [a[0]]
for i in range(1, n):
    sums.append(sums[-1] + a[i])

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

Solution (Python):



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

from collections import deque,defaultdict,Counter











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()
sumA = sum(A)
MIN = float('inf')
snuke = 0
for i in range(N-1):
    snuke += A[i]
    sumA -= A[i]
    MIN = min(MIN,abs(snuke - sumA))
print(MIN)

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

S = sum(a)
snuke = 0
ans = float('inf')

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

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):
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 sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = INF
    snuke = 0
    arai_san = sum(a)

    for x in a[:-1]:
        snuke += x
        arai_san -= x
        ans = min(ans, abs(snuke - arai_san))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int , input().split()))
total = sum(a)
s = 0
ans = 10**10

for i in range(n - 1):
    s += a[i]
    t = total - s
    ans = min(ans, abs(s - t))

print(ans)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


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


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

    N = ii()
    A = il()
    SM = sum(A)
    for n in range(N - 1):
        A[n + 1] += A[n]

    ret = MAX
    for n in range(N-1):
        ret = min(ret, abs(SM - 2 * A[n]))
    print(ret)


if __name__ == '__main__':
    main()

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

for i in range(N):
    goukei+=S[i]
    D.append(goukei)

T=[]    
for i in range(N-1):
    T.append(abs((goukei-D[i])-D[i]))
    
print(min(T))

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()))
total = sum(A)
snk = A[0]
ari = total - snk
ans = abs(snk - ari)
for i in range(1,N-1):
  snk += A[i]
  ari -= A[i]
  ans = min(ans,abs(snk - ari))

print(ans)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


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


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

    N =ii()
    A = il()
    sm = sum(A)
    for n in range(N-1):
        A[n+1] += A[n]

    ret = MAX
    for n in range(N-1):
        ret = min(ret, abs(-sm+(2*A[n])))
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    R = [A[0]]
    for i in range(1, N):
        R.append(R[-1]+A[i])
    ans = 2*(10**9)
    for i in range(N-1):
        x = R[i]
        y = R[N-1] - R[i]
        ans = min(ans, abs(x-y))
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
s,temp = [],0
for i in range(n):
    temp += a[i]
    s.append(temp)
sn,mi = s[n-1],2000000001
for i in range(n-1):
    snuke = s[i]
    arai = sn-s[i]
    if abs(snuke-arai)<mi:
        mi = abs(snuke-arai)
print(mi)

Solution (Python):
from numpy import cumsum

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

ans = 1000000000000000000
ruiseki = cumsum(a)
sum = ruiseki[len(ruiseki)-1]
for i in range(len(ruiseki)-1):
    x = ruiseki[i]
    y = sum - ruiseki[i]
    ans = min(ans, abs(x-y))

print(ans)

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

l = sum(a)
r = 0
ans = 10**20

for i in a[:-1]:
    l -= i
    r += i
    ans = min(ans, abs(l - r))

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
l=[s]
for i in range(n-1):
 l.append(l[i]-2*a[i])
ans=float("inf")
del l[0]
for i in l:
 ans=min(ans,abs(i))
print(ans)

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
cumsum = np.cumsum(a)
s = cumsum[-1]
m = float('inf')
for i in range(n - 1):
    t = cumsum[i]
    m = min(m, abs(2 * t - s))
print(m)

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

Solution (Python):
n = int(input())
ls = list(map(int,input().split()))
mx = sum(ls)
a = 0
k = float("inf")
for i in range(n-1):
    a += ls[i]
    if k > abs(mx-a*2):
        k = abs(mx -a*2)
print(k)

Solution (Python):
from sys import stdin
from itertools import accumulate
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    s1=list(accumulate(a))
    s2=list(accumulate(reversed(a)))

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

    print(ans)

if __name__=="__main__":
    main()

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

import numpy as np
sumA = np.cumsum(A)

ans = float('inf')
for i in range(0, N-1):
    x = sumA[i]
    y = sumA[-1] - x
    ans = min(abs(x-y), ans)
print(ans)

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

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

su = a[0]
if n == 2:
  ar = a[1]
else:
  ar = sum(a[1:n])
dif = su-ar
mi = abs(dif)
for i in range(1,n-1):
  dif = dif+2*a[i]
  abs_dif = abs(dif)
  if mi > abs_dif:
    mi = abs_dif
print(mi)

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

rusekiwa = [al[0]]

for i in range(1,N):
    rusekiwa.append(rusekiwa[-1] + al[i])


lst = []
for n in range(0,N-1):
    x = rusekiwa[n]
    y = rusekiwa[-1] - rusekiwa[n]
    lst.append(abs(x - y))

print(min(lst))

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

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

Solution (Python):
from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
tmp = list(accumulate(A))[:len(A)-1]
total  = sum(A)

    
ans = min([abs(total-2*a) for a in tmp])
print(ans)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]



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

Solution (Python):
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(accumulate(A))
S = B[-1]

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

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    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] = S[i] + a[i + 1]

    ans = float("inf")
    for i in range(N - 1):
        x = S[i]
        y = S[-1] - x
        cost = abs(x - y)
        if cost < ans:
            ans = cost

    print(ans)


if __name__ == "__main__":
    main()

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

p=sum(a)

snuke=0
ans=10**10
for i in range(n-1):
    snuke+=a[i]
    ans=min(ans,abs(p-2*snuke))
print(ans)

Solution (Python):
import numpy as np

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

b = a[0]
c = a[1:].sum()
ans = abs(b - c)

for i in range(1, n-1):
  temp = a[i]
  b += temp
  c -= temp

  if ans > abs(b-c):
    ans = abs(b-c)
else:
  print(ans)

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

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

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

ans = 10000000000000000000
x = 0
for i in range(n):
    x += a[i]
    if i  < n-1:
        ans = min(ans,abs(total-2*x))

print(ans)

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
ans = 10**18
for i, cumsum in enumerate(accumulate(a), start=1):
    if i==n:
        break
    sunuke = cumsum
    araiguma = total - cumsum
    ans = min(ans, abs(sunuke - araiguma))
    
print(ans)

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

Solution (Python):
N = int(input())
lista = list(map(int, input().split()))
a = 0
b = sum(lista)
ans = abs(lista[0]- (b- lista[0]))

for i in range(N- 1):
  a+= lista[i]
  b-= lista[i]
  if(abs(a- b)< ans):
    ans = abs(a- b)
    
print(ans)

Solution (Python):
from itertools import accumulate


N = int(input())
A = list(accumulate(map(int, input().split())))
print(min(abs(A[N - 1] - 2 * A[i]) for i in range(N - 1)))

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

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

x = [0] * (N+1)

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

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

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

total = sum(A)
ans = 10**10
res = 0

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

print(ans)

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

s = sum(a)

ans= 10**18

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

    ans = min(ans,abs(subtotal - (s - subtotal)))


print(ans)

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

    s = [0] * N
    s[0] = a[0]
    sr = [0] * N
    sr[0] = a[-1]

    for i in range(1, N):
        s[i] = s[i-1] + a[i]
        sr[i] = sr[i-1] + a[N-i-1]

    ans = 10 ** 18
    for i in range(N-1):
        tmp = abs(s[i] - sr[N-i-2])
        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools
N = int(input())
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = sum(a)
ans = 10**100
for i in range(N-1):
    ans = min(ans,abs(ruiseki[i]*2-b))
print(ans)

Solution (Python):
import itertools

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

su = sum(a)
ruisekiwa = list(itertools.accumulate(a))
ruisekiwa.pop()
ans = 10**99

for i in ruisekiwa:
  ans = min(ans,abs(su - 2*i))
  
print(ans)

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

candidates = []
snuke = 0
for a in A:
    snuke += a
    raccoon = total - snuke
    result = abs(snuke - raccoon)
    candidates.append(result)

print(min(candidates))

Solution (Python):
from itertools import accumulate
n = int(input())
aaa = list(map(int, input().split()))
a_sum = list(accumulate(aaa))
ans = 1e10
for i in range(n - 1):
    ans = min(ans, abs(a_sum[i] - a_sum[n - 1] + a_sum[i]))
print(ans)

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

X = sum(A)
x = 0
ans = 10000000000007

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

print(ans)

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

X = sum(A)
x = 0
ans = 10000000000007

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

print(ans)

Solution (Python):
import sys

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().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(0, N-1):
    ans = min(ans, abs((S[N] - S[i+1]) - (S[i+1] - S[0])))

print(ans)

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

from itertools import accumulate

lin = list(accumulate(li))
mi = 10**18
S = sum(li)

for i in range(n-1):
    ara = lin[i]
    sunu = S-ara
    mi = min(mi,abs(ara-sunu))

print(mi)

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

total = sum(A)
x = 0
ans = 10000000007

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

print(ans)

Solution (Python):
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()

sum_a = sum(a)
ans = 10**19
s = [0]*(n+1)
for i in range(n-1):
    s[i+1] = s[i]+a[i]
    
    tmptmp = sum_a-s[i+1]
    
    
    x = abs(s[i+1]-tmptmp)
    ans = min(ans, x)
print(ans)

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

    tot = sum(A)

    ans = (10 ** 9) * (2 * 10 ** 5) + 1
    s = 0
    for x in A[:-1]:
        s += x + x
        diff = abs(tot - s)
        if ans > diff:
            ans = diff

    print(ans)


if __name__ == '__main__':
    main()

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

def resolve():
    from itertools import accumulate

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

    B = [0] + A
    B = list(accumulate(B))  

    ans=10**18
    for i in range(1, N):
        snuke=B[i]
        araiguma=B[N]-B[i]
        ans=min(ans,abs(snuke-araiguma))
    print(ans)
resolve()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
su = sum(a)
acc = list(itertools.accumulate(a))
b = [abs((su-acc[i]) - acc[i]) for i in range(n-1)]

print(min(b))

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

total = sum(a)
b = list(itertools.accumulate(a))

ans = pow(10, 12)
for i in range(n-1):
    ans = min(abs(b[i] - (total - b[i])), ans)

if n == 2:
    print(abs(a[0] - a[1]))
    exit()
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 = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x==y:
  ans = 0
else:
  ans = abs(x-y)

for i in range(1,N-1):
  x += a[i]
  y -= a[i]
  if x==y:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)

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

a = 0
for i in range(N):
  a += A[i]
  r[i+1] = a
minimum = 10**18
for i in range(1,N):
  snuke = r[i]
  arai = r[N]-r[i]
  if minimum > abs(snuke-arai):
    minimum = abs(snuke-arai)
print(minimum)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
if N==2:
    print(abs(A[0]-A[1]))
    exit()
SUM=sum(A)
ans=float("INF")
now=0
for i in range(N-1):
    now+=A[i]
    ans=min(ans, abs(now-(SUM-now)))


print(ans)

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