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.



Sample input:
6
1 2 3 4 5 6


Sample output:
1

Submission status: Accepted

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

Submission status: Accepted

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

x = sum(A)
y = 0
res = 10 ** 18

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

print(res)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
s = sum(a)
t = 0
ans = float("inf")
for k in range(N-1):
    t += a[k]
    s -= a[k]
    ans = min(ans,abs(s-t))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    *cumsum, = accumulate(A)
    ans = inf
    for c in cumsum[:-1]:
        d = cumsum[-1] - c
        ans = min(ans, abs(d-c))
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = [0] * (N+1)
    for i in range(N):
        S[i+1] = S[i] + A[i]
    ans = 10**19
    for i in range(1, N):
        a = S[i] - S[0]
        b = S[N] - S[i]
        ans = min(ans, abs(a-b))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    g1 = a[0]
    g2 = sum(a[1:n])
    ans = abs(g1 - g2)
    if n > 2:
        for i in range(1, n-1):
            g1 += a[i]
            g2 -= a[i]
            tmp = abs(g1 - g2)
            if tmp < ans:
                ans = tmp

    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
sumA = 0
sumli = sum(a)
ans = 1000000000
for i in range(n-1):
    sumA += a[i]
    sumB = abs(sumli - sumA*2)
    ans = min(ans,sumB)
if n == 2:
    print(abs(a[0]-a[1]))
else:
    print(ans)

Submission status: Accepted

Solution code:
def splittingplie(n , a):

    ans = 10**18
    allsum = int(sum(a))
    asum = 0

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

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate

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

cumsum = list(accumulate(lst))

mi = 2 * 10 ** 9
su = cumsum[-1]
for i in range(len(cumsum)-1):
  mi = min(mi, abs(cumsum[i] - (su-cumsum[i])))
print(mi)

Submission status: Accepted

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

s = sum(a)
ans = 10**18
t = 0
l = 0
for i in range(N-1):
    t += a[i]
    l = s-t
    b = abs(t-l)
    ans = min(ans,b)

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

n = int(input())
a = [int(i) for i in input().split()]
ac = list(accumulate(a))
d = float("inf")
for i in range(n - 1):
    d = min(abs(ac[i] * 2 - ac[-1]), d)
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

sm=0
s_rui=[]
for tmp in a:
    sm+=tmp
    s_rui.append(sm)

a.reverse()
sm=0
a_rui=[]

for tmp in a:
    sm+=tmp
    a_rui.append(sm)
a_rui.reverse()

mn=10**10

for i in range(N-1):
    diff = abs(s_rui[i] - a_rui[i+1])
    if mn > diff:
        mn=diff

print(mn)

Submission status: Accepted

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

x = 0
y = sum(a)
ans = float("inf")
for i in range(n):
    x += a[i]
    y -= a[i]
    if not i == n - 1:
        ans = min(ans, abs(x - y))
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
s=A[0]
k=sum(A)-s
ans=abs(s-k)
for i in range(1,N-1):
    s+=A[i]
    k-=A[i]
    ans=min(ans,abs(s-k))

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())

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

sA=[A[0]]
siA=[A[-1]]

for i in range(N-1):
    sA.append(sA[i]+A[i+1])
    siA.append(siA[i]+A[-(i+2)])

ans=10**15

for i in range(N-1):
    ans=min(ans,abs(sA[i]-siA[-(i+2)]))

# print(sA,siA)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
sunuke = sum(A)
ara = 0
ans = float("inf")
for i in range(N-1, 0, -1):
    sunuke -= A[i]
    ara += A[i]
    ans = min(ans, abs(sunuke - ara))
print(ans)

Submission status: Accepted

Solution code:
def solve(n, A):
    total = sum(A)
    x = A[0]
    ret = abs(2 * x - total)
    for i in range(1, n - 1):
        x += A[i]
        y = total - x
        if abs(x - y) < ret:
            ret = abs(x - y)
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Accepted

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

total = sum(a)

x = 0
arr = []
if n == 2:
    arr.append(abs(a[0]-a[1]))
else:
    for i in range(n-1):
        x += a[i]
        y = total - x
        arr.append(abs(x - y))

print(min(arr))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
x = sum(A)-A[0]
y = A[0]
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

for i in range(1, n-1):
    sub -= 2 * a[i]
    if abs(sub) < asub:
        asub = abs(sub)
print(asub)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

for i in range(1, n - 1):
    sub -= 2 * a[i]
    if abs(sub) < asub:
        asub = abs(sub)
print(asub)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))

sum_a = sum(A)
x = 0
ans = 1000000000000000

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
res = np.cumsum(a)
ans = 1000000000000
for i in range(N-1):
    ans = min(ans, abs(res[-1]-res[i]*2))

print(ans)

Submission status: Accepted

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

sum_A = sum(A)
tot = 0
ans = float("inf")

for i in range(N - 1):
	tot += A[i]
	ans = min(ans, abs(sum_A - tot - tot))
	
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
arai = sum(A)
sunuke = 0
ans = 10000000000000000
for i in A[:-1]:
    arai -= i
    sunuke += i
    x = abs(sunuke - arai)
    if x < ans:
        ans = x
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int, input().split()))

s = ls[0]
a = sum(ls) - ls[0]

ans = abs(s - a)

for i in range(1, n - 1):
	s += ls[i]
	a -= ls[i]
	sa = abs(s - a)
	if sa < ans:
		ans = sa

print(ans)

Submission status: Accepted

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

csum1 = [A[0] for _ in range(N)]
for i in range(1,N):
  csum1[i] = csum1[i-1]+A[i]
csum2 = [A[-1] for _ in range(N)]
for i in range(N-2,-1,-1):
  csum2[i] = csum2[i+1]+A[i]

ans = float('inf')
for i in range(N-1):
  ans = min(abs(csum1[i]-csum2[i+1]),ans)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:29:09 2020

@author: H_Hoshigi
"""
import sys

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


#sunuke = a_list[0]
#araiguma = sum(a_list[1:])
#min_difference = abs(sunuke - araiguma)
sunuke = 0
sum_a = sum(a_list)

min_difference = sys.maxsize
#abs(sunuke - araiguma)は、abs(sum(a_list)-sunuke*2)として求められる。

#range(1,N-1)ではなく、最初の一枚目から比較する形にした。
for i in range(N-1):
    sunuke += a_list[i]
    #araiguma -= a_list[i]
    min_difference = min(min_difference,
                         abs(sum_a - 2*sunuke))

print(min_difference)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 28 00:14:43 2020

@author: H_Hoshigi
"""

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

sunuke = a_list[0]
araiguma = sum(a_list[1:])
min_difference = abs(sunuke - araiguma)

for i in range(1,N-1):
    sunuke += a_list[i]
    araiguma -= a_list[i]
    min_difference = min(min_difference,
                         abs(sunuke - araiguma))

print(min_difference)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
l = list(map(int,input().split()))
sum_l = sum(l)
min_dif = abs(sum_l-2*l[0])
acum_sum = l[0]
for i in range(1,n-1):
    acum_sum += l[i]
    if min_dif > abs(sum_l - 2*acum_sum):
        min_dif = abs(sum_l - 2*acum_sum)
#print(acum_sum)
print(min_dif)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a[i] for i in range(1, n))
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)

Submission status: Accepted

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)
#print(cumArray)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
from itertools import accumulate

A=list(accumulate(A))
max_= float("inf")

for a in A[:-1]:
    max_=min(max_,abs(A[-1]-2*a))
print(max_)

Submission status: Accepted

Solution code:
import sys
import itertools

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    X = list(itertools.accumulate(A))
    Y = sum(A)

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

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

answer = 10 ** 15
for i in range(N - 1):
  answer = min(answer, abs(Sf[i] - Sb[i + 1]))
  
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
    buff = abs(x - y)
    if buff < ans:
        ans = buff

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
answer = float('inf')
araisan_sum = sum(a) - a[0]
snuke_sum = a[0]
if len(a) == 2:
    answer = abs(snuke_sum - araisan_sum)
else:
    for i in range(1, n-1):
        snuke_sum += a[i]
        araisan_sum -= a[i]
        if answer >= abs(snuke_sum - araisan_sum):
            answer = abs(snuke_sum - araisan_sum)

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]

all_sum = sum(nums)
accum = 0
ans = float('inf')
for i in range(N-1):
    accum += nums[i]
    ans = min(ans, abs(all_sum - 2 * accum))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
An = list(map(int, input().split()))

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

s = A[0]
a = sum(A)-A[0]
ans = abs(s-a)

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = [0]
for i in range(N):
    s.append(s[i] + a[i])
y = s[N] - s[1]
min = abs(s[1] - y)
for i in range(1,N):
    y = s[N] - s[i]
    ans = abs(s[i]-y)
    if ans < min:
        min = ans
print(min)

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())

ret = 10 ** 15

s = 0
t = sum(a)
a.pop()  # 最後の要素は取れない
for x in a:
    s += x
    t -= x
    ret = min(ret, abs(s - t))

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
sum = 0
for i in range(N) :
    sum+=a[i]
ans = 2000000000
suma = 0
for i in range(N) :
    suma += a[i]
    d = abs(sum - 2 * suma)
    if i + 1 < N :
        ans = min(d,ans)
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    leftThanMe = [0 for _ in range(N+1)]
    rightThanMe = [0 for _ in range(N+1)]
    for i in range(N-1):
        leftThanMe[i+1] = A[i] + leftThanMe[i]
    for i in range(1, N)[::-1]:
        rightThanMe[i-1] = A[i] + rightThanMe[i]
    ans = inf
    for i in range(N-1):
        val = abs(leftThanMe[i] + A[i] - rightThanMe[i])
        ans = min(ans, val)
    print(ans)
main()

Submission status: Accepted

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


s = sum(a)
subsum = 0
res = 1001001001001001
for i in range(n-1):
    subsum += a[i]
    remain = s - subsum
    res = min(res, abs(remain-subsum))

print(res)

Submission status: Accepted

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

X = sum(a)
ans = float("inf")
x = 0
for i in range(n):
    x += a[i]
    if (i + 1) < n:
        ans = min(ans, abs(X - 2 * x))

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[i-1]+a[i])
#print(b)
ans=float("inf")
for i in range(n-1):
    ans=min(abs((b[-1]-b[i])-b[i]),ans)
print(ans)

Submission status: Accepted

Solution code:

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

from operator import add
from itertools import accumulate

L = list(accumulate(A, add))

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
sum_ls = [i for i in accumulate(a_ls[:-1])]
sum_a = sum(a_ls)
sum_ls.sort()
ind = bisect.bisect_left(sum_ls, sum_a / 2)
best = 10 ** 18
if ind < n - 1 and abs(sum_a / 2 - sum_ls[ind]) * 2 < best:
    best = abs(sum_a / 2 - sum_ls[ind]) * 2
if ind > 0 and abs(sum_a / 2 - sum_ls[ind - 1]) * 2 < best:
    best = abs(sum_a / 2 - sum_ls[ind - 1]) * 2
print(int(best))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=a[0]
y=sum(a)-a[0]
mini=float('inf')
if n==2:
    print(abs(a[0]-a[1]))
    exit()
for i in range(1,n-1):
    x+=a[i]
    y-=a[i]
    mini=min(mini,abs(x-y))
print(mini)

Submission status: Accepted

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

A_cum = A

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

A_cum_all = A_cum[-1]
ans = float('inf')

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
    a[i]+=a[i-1]
ABS=10**15
for i in range(n-1):
    ABS=min(abs(a[-1]-2*a[i]),ABS)
print(ABS)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int,input().split()))
x = np.array([0]*(N))
suma = sum(a)
for i in range(1,N):
    x[i] = x[i-1] + a[i-1]
y = np.array([suma]*(N))-x
ans = list(map(abs,x-y))
print(min(ans[1:]))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 2:
  ans = abs(A[0]-A[1])
else:
  import numpy
  s = numpy.cumsum(A)
  sA = s[-1]
  ar = numpy.abs(sA-s-s)
  ans = min(ar[1:N-1])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
B = [A[0]]
for i in range(1,N):
    B.append(B[-1]+A[i])
ans = 10**18
for i in range(N-1):
    diff = abs(B[i]-(S-B[i]))
    if diff < ans:
        ans = diff
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cums = [0]
for i in a:
    cums.append(cums[-1] + i)

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int64)

acum = a.cumsum()
total = acum[-1]
dif = np.abs(total-2*acum)
ans = dif[:-1].min()

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]

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

Submission status: Accepted

Solution code:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
acc = list(accumulate(a))
# print(acc)

ans = float('INF')
for i in range(n-1):
    if abs(acc[-1] - acc[i] * 2) < ans:
        ans = abs(acc[-1] - acc[i] * 2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
su = 0
for i in range(0,N-1):
    su = su + a[i]
    ar = deck - su
    ans = min(ans, abs(su-ar))
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
snuke = np.cumsum(A)[:-1]
kuma =  sum_A - snuke

ans = min(abs(snuke-kuma))
 
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

snuke = np.cumsum(A)[:-1]
kuma =  np.cumsum(A[::-1])[:-1]

ans = min(abs(snuke-kuma[::-1]))

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
tmp=[]
X=sum(a)
x=0
ans=1000000000000000000
for i in range(N):
    x+=a[i]
    if i+1<N:
        ans=min(ans,abs(X-2*x))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
s = sum(a)
snuke = 0
raccoon = s
ans = 10**15

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
li = [int(x) for x in input().split()]
X = list(accumulate(li))

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

Submission status: Accepted

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

from itertools import accumulate

acum = list(accumulate(a))

answer = float("inf")
for i in range(N-1):
    answer = min(answer, abs(acum[-1]-acum[i]*2))

print(answer)

Submission status: Accepted

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

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

ans = 10**18
for i in range(N-1):
    left = a_cum[i]
    right = a_sum - a_cum[i]
    if abs(right - left) < ans:
        ans = abs(right - left)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
X = sum(A)
ans = float("inf")
x = 0
for i in range(N):
    x += A[i]
    if i < N-1:
        ans = min(ans, abs(X - 2 * x))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = [0]
if (n == 2):
    print(abs(a[0] - a[1]))
else:
    for i in range(n):
        s.append(a[i] + s[i])

    b = 1e+9
    j = 1
    
    while(j < n):
        if (abs(s[j] - (s[n] - s[j])) < b):
            b = abs(s[j] - (s[n] - s[j]))
        j += 1
    print(b)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
X=[int(x) for x in input().split()]
Y=np.cumsum(X)
P=sum(X)
answer=float('inf')
for i in range(N-1):
  answer =min (answer,abs(P-2*Y[i]))
print(answer)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
s=sum(a)
c=0
b=[]
for i in range(n-1):
    c+=a[i]
    b.append(c)
mi=abs(s-2*b[0])
for i in range(n-1):
    mi=min(mi,abs(s-2*b[i]))
print(mi)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(a, total_sum_a, x, y, abs(x - y)[:-1])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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