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)
X = A[0]
p = abs(2 * X - S)
for i in range(1, N-1):
  X += A[i]
  if p > abs(2 * X - S):
    p = abs(2 * X - S)
  if p == 0:
    break
print(p)

Solution (Python):
import sys
input = sys.stdin.readline
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.append(abs(x - y))
print(min(ans))

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

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

Solution (Python):
import sys

N= int(input())

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


S = [0]*(len(A)+1)

for i in range(1, len(S), 1):

    S[i] = S[i-1] + A[i-1]

x = 0
y = 0
min = float('inf')

for i in range(1, N, 1):
    x = S[i]
    y = S[len(S)-1] - S[i]

    if min > abs(x-y):
        min = abs(x-y)
print(min)

Solution (Python):
import sys

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

def main():
    x = 0
    y = sum(a)
    res = []
    for i in range(n-1):
        x += a[i]
        y -= a[i]
        res.append(abs(x - y))

    return min(res)

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

Solution (Python):
n,*a=map(int,open(0).read().split())
from numpy import*
s=sum(a)
a=array(a[0:n-1])
asum=a.cumsum()
b=(s-2*asum)
print(min(abs(b)))

Solution (Python):
n,*a=map(int,open(0).read().split())
from numpy import*
a=array(a)
asum=a.cumsum()

b=(asum[-1]-2*asum)

print(min(abs(b[0:n-1])))

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

import itertools
ac_al = list(itertools.accumulate(al))

ans = float("inf")  

for a in ac_al[:n-1]:
    tmp = abs((ac_al[-1] - a) - a)
    ans = min(ans, tmp)

print(ans)

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

a_sum = sum(a)
x = a[0]
y = a_sum - x
min_diff = 10000000000
diff = abs(y - x)

for i in range(1, n-1):
    x += a[i]
    y -= a[i]
    diff = abs(y - x)
    if diff < min_diff:
        min_diff = diff

if diff < min_diff:
    min_diff = diff
print(min_diff)

Solution (Python):
import numpy as np

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

x = a.cumsum()
total_sum_a = a.sum()
y = total_sum_a - x



print(min(abs(x - y)[:-1]))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] = a[i] + a[i - 1]
ans = abs(a[-1] - 2 * a[0])
for i in range(1, n - 1):
	ans = min(ans, abs(a[-1] - 2 * a[i]))
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[-1]-B[i])-B[i]))
print(ans)

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

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

min = 0

left = []
for i in range(n-1):
    left.append(a[i])
    if i > 0:
        left[i] += left[i-1]

a.reverse()

right = []
for i in range(n-1):
    right.append(a[i])
    if i > 0:
        right[i] += right[i-1]

right.reverse()

min = 0
for i in range(1,n):
    if i == 1:
        min = abs(left[i-1] - right[i-1])
    else:
        if min > abs(left[i-1] - right[i-1]):
            min = abs(left[i-1] - right[i-1])

print(min)

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

Solution (Python):

n=int(input())
lists=list(map(int,input().split()))
SUM=sum(lists)
subsums=0
MIN=10**100
for i in range(n-1):
    subsums+=2*lists[i]
    MIN=min(MIN,abs(SUM-subsums))
print(MIN)

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

Solution (Python):
import bisect

n = int(input())
l = [int(i) for i in input().split()] 
y=sum(l)

ll=[]
x=0

for i in range(n-1):
    y-=l[i]
    x+=l[i]
    
    ll.append(abs(x-y))

print(min(ll))

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

ans = 10**18
Rui = []
r = 0
for i in range(n):
    r += A[i]
    Rui.append(r)

for i in range(0,n-1):
    can = abs(2 * Rui[i] - Rui[-1])
    if can <= ans:
        ans = can
print(ans)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(A))

acc_a

maxs = 100000000000
if N>2:
    for i in range(1,len(acc_a)-1):
        if abs((acc_a[-1] - acc_a[i])   - acc_a[i])< maxs:
            maxs=abs(acc_a[-1] - 2*acc_a[i])
else:
    maxs=abs(A[1] - A[0])

print(maxs)

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

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

asc = [0] * N
dec = [0] * N

asc[0] = A[0]
dec[-1] = A[-1]

for i in range(1, N):
  asc[i] = asc[i-1] + A[i]
  dec[-i-1] = dec[-i] + A[-i-1]

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

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
ruiseki = [0 for _ in range(n)]
ruiseki[0] = a[0]
for i in range(1, n):
  ruiseki[i] = ruiseki[i-1] + a[i]

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

Solution (Python):
import sys

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

Sc = list()

dp = [10**9] * (n-1)
ep = [10**9] * (n-1)
s = sum(As)

if n-2 == 0:
    print(abs(As[0] - As[1]))
    sys.exit()

for i in range(n-2):
    if i == 0:
        dp[i] = As[i]
    else:
        dp[i] = dp[i-1] + As[i]
    ep[i] = abs(dp[i] - s + dp[i])


print(min(ep))

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a_sum = np.cumsum(a)
sunuke = 0
res = 10**19
for i in range(n-1):
  sunuke += a[-i-1]
  if(abs(sunuke-a_sum[-i-2]) < res):
    res = abs(sunuke-a_sum[-i-2])
print(res)

Solution (Python):
def c_splitting_pile():
    
    
    from itertools import accumulate
    N = int(input())
    A = [int(i) for i in input().split()]
    total = sum(A)
    return min([abs(total - 2 * x) for x in accumulate(A[:-1])])

print(c_splitting_pile())

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

a_sum = [0]*N
cur = 0
for i in range(0,N):
    cur += a[i]
    a_sum[i] = cur

ans = abs(cur-2*a_sum[0])
for i in range(1,N-1):
    if ans > abs(cur-2*a_sum[i]):
        ans = abs(cur-2*a_sum[i])

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    sum_a=sum(aa)
    s=0
    ans=10**16
    for a in aa[:-1]:
        s+=a
        cur=abs(sum_a-2*s)
        if cur<ans:ans=cur
    print(ans)
main()

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

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

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

Solution (Python):
from itertools import accumulate

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

s = list(accumulate(a))

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

Solution (Python):





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

memo = sum(a)



q=a[0]
b=memo-a[0]

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

    ans = min(ans,abs(q-b))
    
print(ans)

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

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

Solution (Python):
import itertools

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

s = sum(a)
ac = list(itertools.accumulate(a))


ans = 10**20

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

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

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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
su = sum(a)
pref = a[0]
suf = su - pref
ans  = abs(suf-pref)
for i in range(1,len(a)-1):
    pref+=a[i]
    suf = su-pref
    ans  = min(ans,abs(pref-suf))

print(ans)

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

left = [0]*(n+1)
right = [0]*(n+1)

for i in range(n):
  left[i+1] = left[i] + aa[i]
  right[i+1]= right[i] +aa[-i-1]

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

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

s = sum(a)
b = s
ans = 10**10
for i in range(1, n):
    b -= a[-i]
    tmp = abs(2*b - s)
    ans = min(ans, tmp)
print(ans)

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

memo = [0 for _ in range(n+1)]

for i in range(n):
    memo[i+1] = memo[i] + l[i]
    
ans = 10 ** 18

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

print(ans)

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

s_total = a[0]
r_total = sum(a)-a[0]
ans = abs(s_total - r_total)

for i in range(1, n-1):
    s_total += a[i]
    r_total -= a[i]
    diff = abs(s_total - r_total)
    if ans > diff:
        ans = diff

print(ans)

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

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

Solution (Python):
from itertools import accumulate

N = int(input())
a = list(map(int, input().split(' ')))
suma = list(accumulate(a))
ans = 10**18
for i in range(N-1):
    ans = min(ans, abs((suma[-1]-suma[i])-suma[i]))

print(ans)

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

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

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

c1 = a[0]
c2 = sum(a) - a[0]

ans = abs(c2 - c1)
for i in range(1, len(a) - 1):
    c1 += a[i]
    c2 -= a[i]
    ans = min(ans, abs(c2 - c1))
print(ans)

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

dp = [0] * N
dp[0] = a[0]

a_sum = sum(a)
a_min = float('inf')
for i in range(N-1):
    if (i == 0):
        dp[0] = a[0]
    else:
        dp[i] = dp[i-1] + a[i]
    if (a_min > abs((a_sum-dp[i]) -dp[i])):
        a_min = abs((a_sum-dp[i]) -dp[i])

print(a_min)

Solution (Python):
N=int(input())
import numpy as np
A=np.array(input().split(),dtype=int)
A=np.cumsum(A)

ans=10**9*2+1
for i in range(N-1):
  ans=min(ans,abs(A[i]-(A[len(A)-1]-A[i])))
print(ans)

Solution (Python):
from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

lin = list(accumulate(li))
su = sum(li)
mi = 10**10

for i in range(n-1):
    mi = min(mi,abs(su-lin[i]*2))
print(mi)

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

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

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

Solution (Python):
n = int(input())
sticks = list(map(int, input().split()))
s = sum(sticks)

a = []
sum_i = 0
for i, v in enumerate(sticks):
  sum_i += v
  if i == len(sticks) - 1:
    continue
  a.append(abs(s - 2*sum_i))

print(min(a))

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

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

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

Solution (Python):
from itertools import accumulate

N = int(input())
a = list(map(int, input().split()))
A = list(accumulate(a))
ans = float('inf')
for i in range(N - 1):
    ans = min(ans, abs(A[i]-(A[N-1]-A[i])))
print(ans)

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


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

    D0 = A[0]
    D1 = sum(A[1:])
    M0 = [None] * (N-1)
    M0[0] = D0 - D1

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

    M0 = list(map(lambda x: abs(x), M0))
    print(min(M0))


main()

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
dp = [0] * N
dp[0] = sum(a)
res = float("inf")
for i in range(N - 1):
  dp[i + 1] = dp[i] - a[i]
for i in range(1, N):
  res = min(abs(2 * dp[i] - dp[0]), res)
print(res)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
d = sum(A)
mi = 1<<100
for i in range(N-1):
    d -= 2 * A[i]
    mi = min(mi, abs(d))
print(mi)

Solution (Python):
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = float("inf")
    s = a[0]
    su = sum(a) - a[0]
    ans = min(ans , abs(s - su))
    for i in range(1, n-1):
        s += a[i]
        su -=a[i]
        ans = min(ans, abs(s - su))
    print(ans)
    



if __name__ == '__main__':
    main()

Solution (Python):

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

ruiseki = [0 for _ in range(n)]
ruiseki[0] = arr[0]

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

inf = 10 ** 20
ans = inf

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

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

Solution (Python):
def examC(inf):
    N = I()
    A = LI()
    sumA = [0]*N
    sumA[0] = A[0]
    cur = inf
    for i in range(N-1):
        sumA[i+1] = sumA[i]+A[i+1]
    for i in range(N-1):
        if cur>abs(sumA[N-1]-sumA[i]*2):
            cur = abs(sumA[N-1]-sumA[i]*2)
    ans = cur
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(inf)

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

snuke = A[0]
arai = sum(A[1:])
ans = abs(arai - snuke)
for a in A[1:n-2]:
    snuke += a
    arai -= a
    ans = min(ans, abs(snuke - arai))

print(ans)

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

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

sum = sum(data)
min = 10**16
x = 0;

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

    if min > abs(sum-x*2):
        min = abs(sum-x*2)


print(min)

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

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

SUM=sum(A)
MIN=[10**10]*2
L=0
R=SUM
for i in range(N-1):
    L+=A[i]
    R-=A[i]
    if(MIN[0]>abs(L-R)):
        MIN[0]=abs(L-R)
        MIN[1]=i
print(MIN[0])

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
value=A[0]
araiguma=sum(A[1:])
num=int(abs(value-araiguma))
for i in range(1,N-1):
    value+=A[i]
    araiguma-=A[i]
    temp=int(abs(value-araiguma))
    if num>temp:num=temp
print(num)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    S = [i for i in accumulate(A)]
    s = S.pop()
    B = [abs((i*2)-s) for i in S]
    print(min(B))


if __name__ == '__main__':
    main()

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

l = []
x = 0
for a_ in a[:n-1]:
    x += a_
    l.append(abs(sum_a - x*2))

res = min(l)
print(res)

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

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

Solution (Python):
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
snk = np.cumsum(alist)[:-1]
ari = np.cumsum(alist[::-1])[::-1][1:]
print(np.min(np.abs(snk - ari)))

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

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

    sm = sum(A)
    current_sm = 0
    ans = 10 ** 10
    for ai in A[:N-1]:
        current_sm += ai
        x = abs(current_sm - (sm - current_sm))
        ans = min(ans, x)
        
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
accl = list(accumulate([0]+l))
ans = float('Inf')
for i in range(1,n):
    x = accl[i]
    j = abs(2*x - suml)
    ans = min(ans,j)
print(ans)

Solution (Python):
from itertools import accumulate
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
accl = list(accumulate([0]+l))
ans = float('Inf')
for i in range(1,n):
    x = accl[i]
    j = abs(2*x - suml)
    ans = min(ans,j)
print(ans)

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

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

n = int(input())
a = [int(a) for a in input().split()]
s = [None] * n; s[0] = a[0]
for i in range(n-1): s[i+1] = s[i] + a[i+1]

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

print(mixi)

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

n = int(input())
a = [int(a) for a in input().split()]
s = [None] * n; s[0] = a[0]
for i in range(n-1): s[i+1] = s[i] + a[i+1]

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

print(mixi)

Solution (Python):

N = int(input())
l_list = [int(e) for e in input().split()]

ans = 10**9 * 2 * 10 ** 5












x = 0
y = sum(l_list)

for i in range(0,N-1):
    x += l_list[i]
    y -= l_list[i]
    
    if ans > abs(x-y):
        ans = abs(x-y)    
        
print(ans)

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

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

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

Solution (Python):
N = int(input())
Data = list(map(int,input().split()))
sum1 = sum(Data)

ans = 10**15
su = 0
for i in range(0,N-1):
    su += Data[i]
    ku = sum1-su
    diff = abs(su-ku)
    ans = min(ans,diff)
print(ans)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    deck = string_to_int(inputs[0])
    sums = []
    for i, card in enumerate(deck):
        if i == 0:
            sums.append(card)
        else:
            sums.append(sums[i-1] + card)

    min_diff = None
    for i, s in enumerate(sums):
        if i == len(sums) - 1:
            break
        arai = sums[-1] - s
        sunuke = s

        if min_diff is None or min_diff > abs(arai - sunuke):
            min_diff = abs(arai - sunuke)
    return min_diff


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):

import sys
import itertools

def solve(N: int, a: "List[int]"):
    left_sum = list(itertools.accumulate(a))
    right_sum = list(itertools.accumulate(a[::-1]))

    answer = 2*10**9
    for i in range(N-1):
        answer = min(answer,abs(left_sum[i]-right_sum[N-2-i]))
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
s=sum(a)
b=[]
for ai in a:
    if not b:
        b.append(ai)
    elif len(b)==N-1:
        break
    else:
        b.append(b[-1]+ai)
c=[abs(2*x-s) for x in b]
print(min(c))

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
S=[0]*(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):
  tmp=abs(S[N]-S[i]*2)
  ans=min(ans,tmp)
print(ans)

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

Solution (Python):
N=int(input())
li=list(map(int,input().split()))
S=sum(li)
x=li[0]
ans=abs(S-2*x)
for n in range(1,N-1):
    x+=li[n]
    new_ans=abs(S-2*x)
    if ans>new_ans:
        ans=new_ans
print(ans)

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


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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
from itertools import accumulate


def main():
    N, *a = map(int, open(0).read().split())
    a = list(accumulate(a))
    total = a[-1]
    print(min(abs(2 * i - total) for i in a[:-1]))
    return


main()

Solution (Python):
from itertools import accumulate


def main():
    N, *a = map(int, open(0).read().split())
    a = list(accumulate(a))
    total = a[-1]
    print(min(abs(total - 2 * i) for i in a[:-1]))
    return


main()

Solution (Python):
from itertools import accumulate


def main():
    N, *a = map(int, open(0).read().split())
    a = list(accumulate(a))
    total = a[-1]
    print(min(abs(total - 2 * a[i]) for i in range(N - 1)))
    return


main()

Solution (Python):
from itertools import accumulate


def main():
    N, *a = map(int, open(0).read().split())
    a = tuple(accumulate(a))
    total = a[-1]
    print(min(abs(2 * a[i] - total) for i in range(N - 1)))
    return


main()

Solution (Python):
from itertools import accumulate


def main():
    N, *a = map(int, open(0).read().split())
    a = tuple(accumulate(a))
    print(min(abs(2 * a[i] - a[-1]) for i in range(N - 1)))
    return


main()

Solution (Python):
from itertools import accumulate


def main():
    N, *a = map(int, open(0).read().split())
    a = list(accumulate(a))
    total = a[-1]
    print(min(abs(2 * a[i] - total) for i in range(N - 1)))
    return


main()

Solution (Python):
INF = float('inf')


def main():
    N, *a = map(int, open(0).read().split())
    ans = INF
    tmp = 0
    total = sum(a)
    for i in range(N - 1):
        tmp += a[i]
        ans = min(ans, abs(2 * tmp - total))
    print(ans)
    return


main()

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

Solution (Python):
n = int(input())
list_a = list(map(int, input().split()))
sum_a = sum(list_a)
list_dif = []
last_sum = 0
for a in list_a[:-1]:
  list_dif.append(abs(sum_a - 2 * (last_sum + a)))
  last_sum += a
print(min(list_dif))

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

ans = float('inf')
x = 0
y = sum(A)

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

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

print(ans)

Solution (Python):


import numpy as np

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

sum_a = sum(a)
print(min([abs(x - (sum_a - x)) for x in a.cumsum()[:-1]]))

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]
m=s[n-1]
d=10**15
for i in range(n-1):
  d=min(d,abs(m-(2*s[i])))
print(d)

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

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


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    
    sunuke = as_[0]
    araiguma = sum(as_[1:])
    diff = abs(sunuke - araiguma)
    for i in range(1, n - 1):
        sunuke += as_[i]
        araiguma -= as_[i]
        diff = min(diff, abs(sunuke - araiguma))

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