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
from itertools import accumulate
INF = float("inf")


def solve(N: int, a: "List[int]"):
    acc = list(accumulate(a))
    m = INF
    for i in range(N-1):
        buf = abs(acc[i]-(acc[N-1]-acc[i]))
        m = min(m, buf)
    print(m)

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

import sys


def solve(N: int, a: "List[int]"):
    x = [0] * (N+1)
    for i in range(1,N+1):
        x[i] = a[i-1]+x[i-1]

    sum_of = sum(a)
    m = 10000000000000000
    for i in range(1,N):
        m = min(m, abs(sum_of - 2*x[i]))

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

suma = sum(a)
sums = [0]
for i in range(N):
    sums.append(sums[-1] + a[i])

ans = 10**14
for i in range(1, N):
    ans = min(ans, abs(suma - sums[i] * 2))

print(ans)

Solution (Python):
n = int(input())
c = list(map(int,input().split()))
sun = sum(c)
can = []
for i in range(n-1):
  sun -= 2 * c[i]
  can.append(abs(sun))
print(min(can))

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

ans = float("inf")
suml = sum(a)
snuke = 0

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

print(ans)

Solution (Python):


from itertools import accumulate

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

acc=list(accumulate(a))

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

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

res = float("inf")
suma = sum(A)
pa = [0]

for i, a in enumerate(A):
    if i == len(A) - 1:
        break
    pa.append(pa[i] + A[i])
    res = min(res, abs(suma - 2 * pa[i + 1]))

print(res)

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

sumleft = [0]*(n+1)

for i in range(n):
    sumleft[i+1] = sumleft[i] + lst[i]

total = sumleft[-1]
ans = None

for i in range(1,n):
    x = sumleft[i]
    y = total - x
    if ans == None:
        ans = abs(x-y)
    else:
        ans = min(ans,abs(x-y))
print(ans)

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

X, Y = [0]*N, [0]*N
X[0] = a[0]
Y[-1] = a[-1]

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

ans = 99999999999999

for i in range(N-1):
    ans = min(abs(X[i]-Y[i+1]),ans)
print(ans)

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


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

ret = 10**10
for i in range(1, N):
    x = cum[i]
    y = cum[-1] - x
    if abs(x-y) < ret:
        ret = abs(x-y)
    
print(ret)

Solution (Python):

import sys, math, fractions, itertools


def solve(N: int, a: "List[int]"):
    S = sum(a)
    L = [a[0]]
    for i in range(1, N):
        L.append(L[-1] + a[i])
    mx = 1e12
    for i in range(0, N-1):
        d = abs((S - L[i]) - L[i])
        mx = min(d, mx)
    print(mx)
    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())
an = list(map(int,input().split()))
sum_an = sum(an)
from itertools import accumulate
an_acc = list(accumulate(an))[0:-1]
print(min(list(map(lambda x : abs(sum_an-x*2),an_acc))))

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

snuke = a[0]
araiguma = sum(a) - a[0]
ans = abs(snuke - araiguma)

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

print(ans)

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

Solution (Python):
N = int(input())
cards = list(map(int, input().split()))
all_c = sum(cards)
half_c = all_c//2
sum_c = 0
ans = 2*10**14
for idx, num in enumerate(cards):
  if idx == N-1:
    break
  sum_c += num
  ans = min(ans, abs(sum_c*2-all_c))
print(ans)

Solution (Python):


def main(N,A):
    zenbu = sum(A)
    part_sum = [A[0]]
    ans = float("INF")
    for i in range(1,N): 
        ans = min(ans, abs(zenbu-2*part_sum[-1]))
        part_sum.append(part_sum[-1]+A[i])

    print(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 




 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = float("inf")
    
    if N == 2:
        print(abs(A[0] - A[1]))
        sys.exit()
    
    a_sp = []
    for i, val in enumerate(A):
        if i == 0:
            a_sp.append(val)
            continue
        tmp = val + a_sp[i-1]
        a_sp.append(tmp)
        
    for i, val in enumerate(a_sp):
        if i == (len(a_sp)-1):
            break
            
        tmp = abs(val - ((a_sp[-1])-val))
        
        if tmp < ans:
            ans = tmp
            
    print(ans)
        
if __name__ == "__main__":
	main()

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

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

S = sum(A)

k = 0
ans = int(1E18)
for i, a in enumerate(A):
    if i == N-1:
        break
    k += a
    ans = min(ans, abs(2*k-S))

print(ans)

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

Solution (Python):
from itertools import accumulate


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

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

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in range(N-1):
        sum_first += a[i]
        if min_diff > abs(sum_a - 2 * sum_first):
            min_diff = abs(sum_a - 2 * sum_first)

    print(min_diff)

main()

Solution (Python):
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	r = [a[0]]
	for i in range(1,n):
		r.append(r[i-1] + a[i])
	s = sum(a)
	m = []
	for i in range(n-1):
		m.append(abs(2*r[i]-s))
	print(min(m))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]

a_sum = sum(A)

sums = [0] * (N + 1)
diffs = [0] * (N + 1)

for n in range(1, N + 1):
    sums[n] = sums[n - 1] + A[n - 1]
    diffs[n] = abs(a_sum - 2 * sums[n])

diffs.pop(len(diffs) - 1)
diffs.pop(0)

print(min(diffs))

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    if not (a % 3 and b % 3 and (a + b) % 3):
        print("Possible")
    else:
        print("Impossible")
    return


def B():
    _, n = L
    I()
    l = LI()
    l.sort(reverse = True)
    print(sum(l[:n]))
    return


def C():
    n = II()
    a = LI()
    for i in range(n-1):
        a[i + 1] += a[i]
    maxa = a[-1]
    ans = inf
    for i in range(n-1):
        ans = min(ans, abs(2 * a[i] - maxa))
    print(ans)
    return


def D():
    return


if __name__ == '__main__':
    C()

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

ltor=[]
rtol=[]
tmp_ltor=0
tmp_rtol=0
for i in range(N):
    tmp_ltor+=a[i]
    ltor.append(tmp_ltor)
    tmp_rtol+=a[N-1-i]
    rtol.append(tmp_rtol)
num=2*10**9
for i in range(N-1):
    num=min(num,abs(ltor[i]-rtol[N-1-i-1]))
print(num)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
S=sum(a_list)
x=0
ans=10**20
for i in range(n-1):
    x+=a_list[i]
    y=S-x
    temp=abs(x-y)
    ans=min(ans,temp)
print(ans)

Solution (Python):
n=int(input())
a_list=list(map(int,input().split()))
S=sum(a_list)
x=0
ans=10**20
for i in range(n-1):
    x+=a_list[i]
    y=S-x
    temp=abs(x-y)
    ans=min(ans,temp)
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 = 10**10
for i in range(1,N):
    ans = min(ans,abs(b[N]-2*b[i]))
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
left = 0
right = sum(A)
ans = float('inf')
for a in A[:-1]:
    left += a
    right -= a
    ans = min(ans, abs(left-right))
    
print(ans)

Solution (Python):
import numpy as np
N = int(input())
a = list(map(int,input().split()))
tmp = a[0]
S = sum(a)
ans = np.abs(S-2*tmp)
for i in range(1,N-1):
    tmp += a[i]
    ans = min(ans,np.abs(S-2*tmp))
    
print(ans)

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]

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

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

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

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

left = [0] * N
right = [0] * N

left[0] = a[0]
right[-1] = a[-1]
for i in range(1, N):
    left[i] = a[i] + left[i-1]
for i in range(N-2, -1, -1):
    right[i] = a[i] + right[i+1]



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

Solution (Python):



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

front = a[0]
back = sum(a[1:])
mi = abs(front - back)
for i in range(1,n-1):
    back -= a[i]
    front += a[i]
    mi = min(mi,abs(front-back))
print(mi)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
sum_arai = sum(A)
sum_sunuke = 0
dif = 0

ans = 10 ** 15

for i in range(N - 1):
    sum_arai -= A[i]
    sum_sunuke += A[i]
    dif = abs(sum_arai - sum_sunuke)
    if dif <= ans:
        ans = dif

print(ans)

Solution (Python):
n,x,*a,b=map(int,open(0).read().split())
y=sum(a)+b
z=abs(x-y)
for i in a:x+=i;y-=i;z=min(z,abs(x-y))
print(z)

Solution (Python):
n,x,*a=map(int,open(0).read().split())
y=sum(a)
z=abs(x-y)
for i in a[:-1]:x+=i;y-=i;z=min(z,abs(x-y))
print(z)

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

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

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

left_sum = [0] * (N - 1)
right_sum = [0] * (N - 1)

left_sum[0] = a[0]
right_sum[0] = a[-1]
for i in range(1,len(a) - 1):
    left_sum[i] = left_sum[i-1] + a[i]

for i in reversed(range(1,len(a) - 1)):
    right_sum[N-1-i] = right_sum[N-2-i] + a[i]


ans = 9999999999999999

for i in range(len(left_sum)):
    ans = min(ans, abs(left_sum[i] - right_sum[N-2-i]))
print(ans)

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

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

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

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

s = sum(a)
l = 0

ans = 10**10
   
for i in range(N-1):
    l += a[i]
    ans = min(ans, abs(s - 2*l))

print(ans)

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

li=[0]*(n+1)

for i in range(n):
    li[i+1]=li[i]+a[i]

all=sum(a)

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

Solution (Python):

N = int(input())

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


x = sum(a)
y = 0
su = N
ans = float("inf")

a.reverse()

for i in a:

        x -= i
        y += i
        su -= 1

        if su != N and su != 0:
            ans = min (ans , abs(x-y))

            

print (ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
for i in range(1,N):a[i] += a[i-1]
lasta = a[N-1]
g = 999999999999
for i in range(N-1):g=min(g,abs(2*a[i]-lasta))
print(g)

Solution (Python):
def main():
    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)


main()

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

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

right_list=[] 
left_list=[] 
diff_list=[] 

right_list.append(l[0])
left_list.append(l[n-1])

for i in range(1,n):
    right_list.append(right_list[i-1]+l[i])
    left_list.append(left_list[i-1]+l[n-1-i])

left_list.reverse()

for i in range(0,n-1):
    diff_list.append(abs(right_list[i]-left_list[i+1]))

print(min(diff_list))

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

sum_card = sum(card)
min_value = 10000000000
sunuke = 0
for i in range(0,N-1,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))

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

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

ls = []
ls.append(a[0])

for i in range(1,n):
    ls.append(a[i]+ls[i-1])

Sum = ls[-1]
ans = 10**20
for i in range(0,n-1):
    ans = min(abs(Sum-2*ls[i]),ans)

print(ans)

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

s = 0
t = 0
a_sum = []
b_sum = []
for i in range(n-1):
    s += a[i]
    a_sum.append(s)
    t += a[n-i-1]
    b_sum.append(t)
ans = 2*(10**14)
for i in range(n-1):
    ans = min(ans, abs(a_sum[i]-b_sum[n-i-2]))

print(ans)

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

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

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

from itertools import accumulate


def main():
    n = int(input())
    lst = tuple(accumulate(map(int, input().rstrip().split())))
    total = lst[-1]
    ans = min(abs(total - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate


def main():
    n = int(input())
    lst = tuple(accumulate(map(int, input().rstrip().split())))
    total = lst[-1]
    ans = min(abs(total - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate


def main():
    n = int(input())
    lst = tuple(accumulate(map(int, input().rstrip().split())))
    ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    n = int(input())
    lst = tuple(map(int, input().rstrip().split()))
    cur, total, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        cur += i
        ans = min(ans, abs(total - cur * 2))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    n = int(input())
    lst = tuple(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()

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

snuke=0
araiguma=sum(a)
ans=10**15

for i in range(N-2):
    snuke+=a[i]
    araiguma-=a[i]
    ans=min(ans,abs(snuke-araiguma))

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

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

Solution (Python):
from itertools import accumulate

N = int(input())

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

f = list(accumulate(A))

b = list(accumulate(A[::-1]))


b = b[::-1]


ans_list = []
for i in range(0, N-1):

    ans_list.append(abs(f[i]-b[i+1]))

print(min(ans_list))

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

Solution (Python):
input()
l = list(map(int,input().split()))
tomato = sum(l)
s = 0
m = 1000000000000
for i in range(len(l)-1):
    s += l[i]
    if(m > abs(s-(tomato-s))):
        m = abs(s-(tomato-s))
print(m)

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

le,ri,le2,ri2 = 0,sum(l),sum(l),0
ans,ans2 = 10**10,10**10
for i in range(len(l)//2):
    le += l[i]
    ri -= l[i]
    le2 -= l[-(i+1)]
    ri2 += l[-(i+1)]
    ans = min(ans,abs(le-ri))
    ans2 = min(ans2, abs(le2-ri2))
    
else:
    print(min(ans,ans2))

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

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    if ans < min(ans,abs(le-ri)):
        print(ans)
        break
    else:
        ans = min(ans,abs(le-ri))
else:
    print(ans)

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

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    if ans < min(ans,abs(le-ri)):
        print(ans)
    else:
        ans = min(ans,abs(le-ri))
else:
    print(ans)

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

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    ans = min(ans,abs(le-ri))
else:
    print(ans)

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

le,ri = 0,sum(l)
ans = []
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    ans.append(abs(le-ri))
else:
    print(min(ans))

Solution (Python):





def main():
    num = int(input())
    data = list(map(int, input().split()))

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

    print(ans)





if __name__ == '__main__':
    main()

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

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

ans = float('inf')

for a in A[:-1]:
    if ans > abs(2*a - sm):
        ans = abs(2*a - sm)

print(ans)

Solution (Python):







num = int(input())
org_list = list(map(int, input().split()))

goukei = sum(org_list)

pre_min_diff = 10**12
wip_sum = 0

for i in range(num-1):
     wip_sum += org_list[i]
     min_diff = abs(goukei - wip_sum*2)
     if min_diff < pre_min_diff:
         pre_min_diff = min_diff

print(pre_min_diff)

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

s = sum(a_list)
mae = 0
min_diff = 10**16
for a in a_list[:-1]:
    mae += a
    ato = s - mae
    diff = abs(mae-ato)
    if diff < min_diff:
        min_diff =diff
print(min_diff)

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

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

Sum = sum(a)
c = 0
difMin = 10**14

for i in range(N-1):
    c += a[i]
    dif = abs(Sum - c*2)
    if dif < difMin:
        difMin = dif

print(difMin)

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

Solution (Python):
from itertools import accumulate

N = int(input())
a = list(map(int, input().split()))
aac = list(accumulate(a))
suma = sum(a)
ans = 1e10
for i in range(0, N - 1):
    ans = min(ans, abs(suma - 2 * aac[i]))

print(ans)

Solution (Python):
n = int(input())
an = [int(i) for i in input().split()]
total = sum(an)
x = 0
ans = abs(2*an[0]-total)
for i in range(n-1):
  x += an[i]
  ans = min(ans, abs(2*x-total))
print(ans)

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

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    s = sum(a)
    ret = float('inf')
    tmp = 0
    for i in range(N - 1):
        tmp += a[i]
        ret = min(ret, abs(tmp - (s - tmp)))
    print(ret)
    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):
import sys
input = sys.stdin.readline

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

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

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

c_sum_left = [0]
total = 0
for i in range(N):
    c_sum_left += [c_sum_left[i] + a[i]]
    total += abs(a[i])

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


ans = total
for i in range(1, N):
    
    ans = min(ans, abs(c_sum_left[i] - c_sum_right[N-i]))
print (ans)

Solution (Python):
N = int(input())
A = [int(s) for s in input().split()]

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), i))    
    abs_list.sort()
    idx = abs_list[0][1]

    left = sum(A[:idx + 1])
    right = sum(A[idx + 1:])
    print(abs(left - right))

if __name__ == '__main__':
    main()

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

s = sum(a)

w = None
for ai in a[:-1]:
  s -= 2 * ai
  if w is None:
    w = abs(s)
  else:
    w = min(w, abs(s))
print(w)

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

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

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

print(ans)

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

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

l.reverse()

x = 0
sum_x = []
sum_y = [sum(l)]*(n-1)
abs_xy = []

for i in range(n-1):
    x += l[i]
    sum_x.append(x)
    sum_y[i] -= sum_x[i]
    abs_xy.append(abs(sum_x[i]-sum_y[i]))


print(min(abs_xy))

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

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

l.reverse()

x = 0

sum_x = []

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

sum_y = [sum(l)]*(n-1)

for i in range(n-1):
    sum_y[i] -= sum_x[i]
    
abs_xy = []

for i in range(n-1):
    abs_xy.append(abs(sum_x[i]-sum_y[i]))

print(min(abs_xy))

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

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

l.reverse()

x = 0

sum_x = []

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

sum_y = [sum(l)]*(n-1)

for i in range(n-1):
    sum_y[i] -= sum_x[i]
    
abs_xy = []

for i in range(n-1):
    abs_xy.append(abs(sum_x[i]-sum_y[i]))

print(min(abs_xy))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n=I()
  l=LI()

  al=sum(l)

  sm=0
  sa=inf
  for x in l[:-1]:
    sm+=x
    sa=min(sa,abs(sm-(al-sm)))

  return sa

print(main())

Solution (Python):
import numpy as np

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

A = np.array(A)
A_cumsum = np.cumsum(A)

solver = []
for i in range(N-1):
  snuke = A_cumsum[i]
  racoon = A_cumsum[-1] - A_cumsum[i]
  solver.append(np.abs(snuke - racoon))
  
print(min(solver))

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

L = A[0]
R = sum(A[1:])
A.pop(0)
A.pop(-1)
ans = abs(L-R)

for a in A:
	L += a
	R -= a
	if abs(L-R) < ans:
		ans = abs(L-R)
print(ans)

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

stim = [0]
ans = float('inf')
for i in a:
    stim.append(stim[-1]+i)
for i in stim[1:len(stim)-1]:
    ans = min(ans,abs(stim[-1]-2*i))
print(ans)

Solution (Python):
n = int(input())
card_list = [ int(v) for v in input().split() ]


s = sum(card_list) 
a = card_list[0]
b = s - a
ans = n*10**9

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

print(ans)

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

Acum = A.cumsum()
total = Acum[-1]
diff = np.abs(Acum - (total-Acum))

answer = diff[:-1].min() 

print(answer)