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:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

ans = 2*(10**9)
S = sum(A)

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
M=[float("inf")]*(N+10)
M[0]=0
for i in range(1,N+1):
	M[i]=M[i-1]+L[i-1]
ans=float("inf")
for i in range(1,N):
	X=M[i]
	Y=M[N]-M[i]
	ans=min(ans,abs(X-Y))
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
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 operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

arr=limii()
sumarr=sum(arr)
xsum=0
ans=10**1000
for i in range(n-1):
    xsum+=arr[i]
    ans=min(ans,abs(xsum-(sumarr-xsum)))
print(ans)

Submission status: Accepted

Solution code:
# Problem C - Splitting Pile

# input
n = int(input())
a_list = list(map(int, input().split()))

# initialization
min_cost = 10**15
arai_score = sum(a_list)
snuke_score = 0

# 累積和による解
for i in range(len(a_list)-1):
    a = a_list[i]
    snuke_score += a
    arai_score = arai_score - a
    min_cost = min(min_cost, abs(snuke_score - arai_score))

# output
print(min_cost)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

import numpy as np
a = list(np.cumsum(a))

ans = 100000000000000000

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

print(ans)

Submission status: Accepted

Solution code:
import numpy

n = int(input())
A = list(map(int, input().split()))
res = numpy.cumsum(A)

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    sumA = [0] * (N + 1)
    for i, a in enumerate(A): sumA[i+1] = sumA[i] + A[i]
    Ans = 100000000000000000
    for i in range(N - 1):
        Ans = min(Ans, abs(sumA[i + 1] - (sumA[N] - sumA[i + 1])))
    print(Ans)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
# a=[0]+a
acc=accumulate(a)
acc=list(acc)

sunuke=0
arai=0
ans=10**18
for i in range(1,n):
    sunuke=acc[i-1]
    arai=s-sunuke
    t=abs(sunuke-arai)
    ans=min(t,ans)
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
s = sum(a)
arr = [0 for _ in range(n)]
arr[0] = a[0]
ans = [inf for _ in range(n)]
ans[0] = abs(a[0] - (s - a[0]))
for i in range(1, n - 1):
    arr[i] = arr[i - 1] + a[i]
    ans[i] = abs(arr[i] - (s - arr[i]))
print(min(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

sunuke = 0
kuma = sum(a)
ans = pow(10, 100)
for i in range(n - 1):
    sunuke += a[i]
    kuma -= a[i]
    #print(sunuke, kuma)
    if abs(kuma - sunuke) < ans:
        ans = abs(kuma - sunuke)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
T = 0
S = sum(A)

ans = 10**18
for a in A[:-1]:
    T += a
    S -= a
    ans = min(ans, abs(T - S))

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    ans = 10**18
    for i in range(1, N):
        snuke = S[i] - S[0]
        arai = S[N] - S[i]
        cur = abs(snuke - arai)
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ruiseki = [0] * (n + 1)

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

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

Submission status: Accepted

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

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

ans=10**19
SUM=sum(A)
for s in CS:
    ans=min(ans,abs(SUM-s-s))
print(ans)

Submission status: Accepted

Solution code:
n = input()

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

max_sum = sum(A)

a,b = A[0],sum(A[1:])
m = abs(a - b)
#print(a, b)
for i in range(1,len(A)-1):
  #print(a+A[i],b-A[i])
  a = a+A[i]
  b = b-A[i]
  f= abs(a- b)
  if f< m:
    m = f
print(m)

Submission status: Accepted

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

total = sum(l)

from itertools import accumulate
x = list(accumulate(l))

y = []
for i in range(n-1):
    y += [abs(total - x[i] - x[i])]

print(min(y))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

N, *A = map(int, open(0).read().split())

s = sum(A)
x = 0
dmin = 10**15
for a in A[:-1]:
  x += a
  dmin = min(abs(s-x-x), dmin)

print(dmin)

Submission status: Accepted

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

s=A[0]
S=sum(A)
ans=abs(sum(A) - 2*s)
for i in range(1,n-1):
	s += A[i]
	ans = min(ans, abs(S - 2*s))

if n > 3:
	print(ans)
else:
	print(abs(A[1]-A[0]))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

goukei = sum(a)
if n == 2:
    print(abs(a[0]-a[1]))
else:
    x = [0] * n
    x[0] = a[0]
    
    ans = 10 ** 11
    for i in range(1,n-1):
        x[i] = x[i-1] + a[i]
        y = goukei - x[i]
        ans = min(ans, abs(x[i]-y))
    
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
M = sum(a)
snk = 0
ans = float('inf')
for i in range(N-1):
    snk += a[i]
    ari = M - snk
    ans = min(ans,abs(snk-ari))
print(ans)

Submission status: Accepted

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

ans = float('inf')
snk = 0
for i in range(N-1):
    snk += a[i]
    ans = min(ans,abs(M-2*snk))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    s = sum(a)
    c = 0
    m = float("inf")
    for i in range(len(a) - 1):
        c += a[i]
        m = min(m, abs(2 * c - s))
    print(m)


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:
INF = 30000000000
N = int(input())
points = list(map(int, input().split()))
sums = [0]
for index in range(len(points)):
  sums.append(points[index]+sums[index])
ans = INF
last = sums[-1]
for s in sums[1:-1]:
  ans = min(ans, abs(last -s - s))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

list = list(map(int, input().split()))
all = sum(list)
ans = 10**10
sunuke = 0

for i in range(0,n-1):
    sunuke += list[i]
    arai = all - sunuke
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)

Submission status: Accepted

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

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

MIN=10**10
for g in range(1,n):
    MIN=min(MIN,abs(accumlate[-1]-2*accumlate[g]))

print(MIN)

Submission status: Accepted

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

su = sum(a)
mini = 10**10
x = 0

for i in range(n-1):
    x += a[i]
    y = su - x
    diff = abs(x - y)

    if diff < mini:
        mini = diff

print(mini)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = float('inf')
c = 0
for ai in a[:-1]:
    c += ai
    ans = min(ans, abs(s-c-c))
print(ans)

Submission status: Accepted

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

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

S = sum(a)
ans = 10000000000000000
for i in range(N - 1):
    ans = min(abs(2 * s[i] - S), ans)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#-----

cumulative_sum=["_"]*len(a_list)
cumulative_sum[0] = a_list[0]
for i in range(1,len(a_list)):
    cumulative_sum[i] = cumulative_sum[i-1] + a_list[i]

diff_list=[]
for v in cumulative_sum[:-1]:
    diff = abs( 2*v - cumulative_sum[N-1] )
    diff_list.append(diff)

print(min(diff_list))

Submission status: Accepted

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

first_half = l[0]
second_half = sum(l[1:])
diff = abs(first_half - second_half)

for i in l[1:len(l)-1]:
    first_half += i
    second_half -= i
    if abs(first_half - second_half) < diff:
        diff = abs(first_half - second_half)

print(diff)

Submission status: Accepted

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

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

x=[0]*N
y=[0]*N
z=[0]*N
for j in range(N):
    x[j]=b[j]
    y[j]=b[-1]-b[j]
    z[j]=abs(x[j]-y[j])

print(min(z[:-1]))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a_L = list(map(int,input().split()))

def get_ruisekiwa(a_L):
    # 累積和
    return [0] + list(itertools.accumulate(a_L))

ans = float("inf")
r = get_ruisekiwa(a_L)

#print(r)
for i in range(1,len(a_L)):
    x = r[i]
    g = r[-1] - r[i]
    ans = min(abs(x-g),ans)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from itertools import accumulate
ans=10**10
a=list(accumulate(a))
for i in range(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()))
S = sum(a)
d = [0]*n
for i in range(1,n): d[i] += d[i-1]+a[i-1]
ans = [abs(S-2*d[i]) for i in range(1,n)]
print(min(ans))

Submission status: Accepted

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

sunuke=A[0]
araiguma=sum(A)-sunuke
ans=abs(sunuke-araiguma)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**10
x = 0
y = sum(a)
for i in range(len(a)-1):
  x += a[i]
  y -= a[i]
  d = abs(x-y)
  if d < ans:
    ans = d
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A = list(accumulate(A))
answer = abs((A[-1] - A[0]) - A[0])
for i in range(N - 1):
    L = A[-1] - A[i]
    K = abs(L - A[i])
    if K < answer:
        answer = K


print(answer)

Submission status: Accepted

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

ans = float('inf')
x = 0
X = sum(a_l)
for a in a_l[:-1]:
    x += a
    ans = min(ans, abs(X - 2*x))

print(ans)

Submission status: Accepted

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

ans = 10**10
x = 0
y = sum(A)
for i in range(0,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()))
sum_a = sum(a)

ans = 10 ** 20
s_sum = 0
for i in range(n - 1):
    s_sum += a[i]
    ans = min(ans, abs((sum_a - s_sum) - s_sum))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  a = list(input_list())
  sa = sum(a)
  ans = 10**10
  r = 0
  for v in list(a)[:-1]:
    r += v
    ans = min(ans, abs(sa - (2*r)))
  print(ans)

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

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Submission status: Accepted

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

cusum = [0]
for a in A:
  tmp = cusum[-1] + a
  cusum.append(tmp)

ans = 5e9
for i in range(1, N):
  p1 = cusum[i]
  p2 = cusum[-1] - cusum[i]
  diff = abs(p1 - p2)
  ans = min(diff, ans)

print(ans)

Submission status: Accepted

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

a_sum = [0]*N
x = 0

for i in range(N):
    x += a[i]
    a_sum[i] = x
    
ans = 10**18+1
sum_a = sum(a)

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
CS=[A[0]]
for i in range(1,N-1):
  CS.append(CS[-1]+A[i])
SUM=sum(A)
ans=10**20
for s in CS:
  ans=min(ans,abs(SUM-s-s))
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])
ans=10**9+10**9+1
for i in range(1,n):
    ans=min(ans,abs(s[n]-s[i]-s[i]))
print(ans)

Submission status: Accepted

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

total = sum(data)
x = 0
ans = 2 * 10**9 + 1
last = data[-1]
for i in range(len(data)-1):
    x += data[i]
    score = abs(2*x - total)
    if score < ans:
        ans = score
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n=int(input())
l=list(map(int,input().split()))
cul=list(itertools.accumulate(l))
sum=cul[-1]
tmp=abs(cul[0]-sum/2)
for i in range(1,n-1):
  if tmp>abs(cul[i]-sum/2):
    tmp=abs(cul[i]-sum/2)
print(int(2*tmp))

Submission status: Accepted

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#067_C
n=int(input())
a=list(map(int,input().split()))
cs=[a[0] for _ in range(n)]
for i in range(n-1):
    cs[i+1]=cs[i]+a[i+1]
abs_cs=[abs(2*cs[i]-cs[-1]) for i in range(n-1)]
print(min(abs_cs))

Submission status: Accepted

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


s = sum(a)
m = pow(10, 20)
b = 0
for i in range(N-1):
    b += a[i]
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    #print(a[i])
print(m)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    
    sum_A = sum(A)
    sub_sum = A[0]
    ret = abs(sum_A-2*sub_sum)
    for a in A[1:-1]:
        sub_sum += a
        if abs(sum_A-2*sub_sum) < ret:
            ret = abs(sum_A-2*sub_sum)
            
    print(ret)
    
solve()

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 a in A[1:-1]:
  x += a
  y -= a
  ans = min(ans, abs(x - y))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
from_left = [A[0]]
from_right = [A[-1]]

for i in range(1, N):
    from_left.append(from_left[-1]+A[i])
    from_right.append(from_right[-1]+A[N-i-1])
from_right.reverse()
ans = float('inf')
for i in range(N-1):
    ans = min(ans, abs(from_left[i]-from_right[i+1]))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    a=LI()
    S=[0]*(N+1)
    
    for i in range(N):
        S[i+1]=S[i]+a[i]
        
    ans=10**20
    for i in range(1,N):
        sn=S[i]
        ar=S[-1]-sn
        temp=abs(sn-ar)
        ans=min(ans,temp)
        
    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

s = 0
l = sum(a)
r = []
for i in a[:-1]:
    s +=i
    k = abs(l-2*s)
    r.append(k)
r.sort()
print(r[0])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = 0
y = sum(a)
ans = 10e9
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:
n = int(input())
a = [int(i) for i in input().split()]
t = sum(a)
ans = 10e9
x = 0
for i in range(n):
    x += a[i]
    if (i + 1 < n):
        ans = min(ans, abs(t - 2*x))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
sum_left,sum_right=a[0],sum(a)-a[0]
mi=abs(sum_left-sum_right)
for i in range(1,n-1):
    sum_left+=a[i]
    sum_right-=a[i]
    if abs(sum_left-sum_right)<mi: mi=abs(sum_left-sum_right)
print(mi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ruisekiwa = [0]*(n+1)
for i in range(n):
    ruisekiwa[i+1] = a[i] + ruisekiwa[i]
ans = 999999999999
for i in range(1,n):
    num = abs(ruisekiwa[i] - (ruisekiwa[-1] - ruisekiwa[i]))
    ans = min(ans,num)
print(ans)

Submission status: Accepted

Solution code:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())

"""
"""

#solution:

#input
N,=pin()
A=list(pin())
S=sum(A)
s=A[0]
m=abs(S-s*2)
#print(m)
for i in range(1,N-1):
    s=s+A[i]
    t=abs(S-s*2)
    #print(t)
    m=min(t,m)
print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
r=sum(a)
l=0
ans=float('INF')
for i in range(n-1):  
    l+=a[i]
    r-=a[i]
    ans=min(ans,abs(l-r))
print(ans)

Submission status: Accepted

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

import itertools
accum = list(itertools.accumulate(a))

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

Submission status: Accepted

Solution code:
def main():
    card_num = int(input())
    cards = list(map(int, input().split()))
    answer = float("inf")
    num_sum = [cards[0]] * card_num
    for i in range(1, card_num):
        num_sum[i] = num_sum[i - 1] + cards[i]
    for i in range(card_num - 1):
        answer = min(answer, abs(2 * num_sum[i] - num_sum[-1]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cumsum = list(itertools.accumulate(a))

min_ = 2 * 10 ** 9
sum_ = cumsum[-1]
for i in range(n-1):
    min_ = min(min_, abs(cumsum[i] - (sum_ - cumsum[i])))

print(min_)

Submission status: Accepted

Solution code:
n = int(input())
lis = [int(x) for x in input().split()]
arai = sum(lis) - lis[0]
sunu = lis[0]
mn = abs(arai - sunu)

for i in lis[1:-1]:
    arai -= i
    sunu += i
    mn = min(mn,abs(arai - sunu))
print(mn)

Submission status: Accepted

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

x=[a[0]]

for i in range(1,n-1):
    x.append(x[i-1]+a[i])
y=[sum(a)-a[0]]
for i in range(1,n-1):
    y.append(y[i-1]-a[i])
#print(x)
#print(y)

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cum = [0]
for i in range(n):
    cum.append(cum[i] + a[i])
#print(cum)

ans = int(1e10)
for i in range(1,n):
    dif = abs(cum[i] - (cum[n]- cum[i]))
    if ans > dif:
        ans = dif
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst1 = list(map(int,input().split()))
s = sum(lst1)
abs_ = 10**18
now = 0
i = 0
while True:
    now += lst1[i]
    if i >= n-1:
        break
    else:
        abs_ = min(abs_,abs(now-(s-now)))
    i += 1

print(abs_)

Submission status: Accepted

Solution code:
import itertools
import operator

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

cumsum = list(itertools.accumulate(a, operator.add))
# print('cumsum', cumsum)

s = cumsum[-1]
min_v = 10**10
for i in range(0, N - 1):
    x = cumsum[i]
    v = abs(2 * x - s)
    if v < min_v:
        min_v = v
print(min_v)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = 0
l = sum(A)
r = []
for a in A[:-1]:
  s += a
  k = abs(l - 2*s)
  r.append(k)
r.sort()
print(r[0])

Submission status: Accepted

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

y = sum(a)
x = 0
ans = 10000000000000000

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

print(ans)

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()
c = [0] * (n + 1)
for i in range(1, n + 1):
    c[i] = c[i - 1] + a[i - 1]

ans = inf
for i in range(n - 1):
    m = i + 1
    ans = min(ans, abs(c[m] - (c[n] - c[m])))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
tmp = [int(x) for x in input().split()]
lst = [tmp[0]]
for x in tmp[1:]:
    lst.append(lst[-1] + x)

total = lst[-1]
ret = 10 ** 100
for i in range(N - 1):
    n = lst[i]
    ret = min(ret, abs(n - (total - n)))
print(ret)

Submission status: Accepted

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

s = 0
t = 0

ans = 10 ** 12

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

for n in range(N-1):
  s += A[n]
  t -= A[n]
  ans = min(ans, abs(s - t))

print(ans)

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = list(map(int,input().split()))

    sm = sum(a)
    sn = a[0]
    ar = sm - a[0]
    ans = abs(sn - ar)

    for i in range(1,len(a)-1):
        sn += a[i]
        ar -= a[i]
        ans = min(ans,abs(sn-ar))

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

sm = sum(a)
sn = a[0]
ar = sm - a[0]
ans = abs(sn - ar)

for i in range(1,len(a)-1):
    sn += a[i]
    ar -= a[i]
    ans = min(ans,abs(sn-ar))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A=sum(a)
s=[0]*(n+1)
ans=float('inf')
for i in range(n-1):
    s[i+1]=s[i]+a[i]
    tem=abs(A-2*s[i+1])
    if tem>=0 and tem<ans:
        ans=tem
print(ans)

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