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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

n = int(input())
l = [int(i) for i in input().split()] 
y=sum(l)
#print(y)
ll=[]
x=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 累積和が見える
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_splitting_pile():
    # X = sum(A)、カードの山の先頭 i 枚の総和を x とすると、
    # |y-x| = |X-2x| である。各 i(1<=i<=N-1) についてこの値を計算すればよい
    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())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

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

ans = 10**20

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
#reverse_a = list(reversed(a))
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)

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]
    temp = abs(x-y)
    if temp < ans:ans = temp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(snuke,arai)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 累積和をととっといて比較
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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]
ans=float("inf")
for i in range(n-1):
    ans=min(ans,abs(a[n-1]-2*a[i]))
print(ans)

Submission status: Accepted

Solution code:
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(':', ai, ans)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#067c
N = int(input())
l_list = [int(e) for e in input().split()]

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

#愚直解
#for i in range(1,N):
#    x = sum(l_list[0:i])
#    y = sum(l_list[i:])
#    
#    print(l_list[0:i],l_list[i:],x,y,x-y,abs(x-y))
#    
#    if ans > abs(x-y):
#        ans = abs(x-y)

#高速解
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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])
dmin = 10**15
for i in range(1,N):
    dmin = min(dmin,abs(B[N]-2*B[i]))
print(dmin)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Splitting Pile

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

total = sum(a)
ans = None
x = 0
for ai in a[:-1]:
    x += ai
    total -= ai
    if ans is None:
        ans = abs(x - total)
    else:
        ans = min(ans, abs(x - total))

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=0
b=sum(A)

temp=10**12
for i in range(N-1):
    a+=A[i]
    b-=A[i]
    temp=min(abs(a-b),temp)

print(temp)

Submission status: Accepted

Solution code:
N = int(input())
I = list(map(int, input().split()))
minX = 10000000000
end = I.pop()
sumI = sum(I)
for i in range(len(I)):
  minX = min(minX, abs(sumI - end ) )
  popped = I.pop()
  sumI -= popped
  end += popped
  
print(minX)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    t = 0
    mt = 10 ** 10
    a = list(map(int, input().rstrip('\n').split()))
    s = sum(a)
    for i in range(n-1):
        t += a[i]
        mt = min(mt, abs(s - t - t))
    print(mt)


if __name__ == '__main__':
    slove()