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: Time Limit Exceeded

Solution code:
n = int(input())
arr = input().split()
x = 0
y = 0
for i in range(n):
    arr[i] = int(arr[i])
min_xy = abs(arr[0] - sum(arr[1:]))
for i in range(1,n):
    x = sum(arr[:i])
    y = sum(arr[i:])
    if min_xy > abs(x - y):
        min_xy = abs(x - y)
print(min_xy)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n = input()
a = map(int, raw_input().split())
t = abs(sum(a[:1]) - sum(a[1:]))

for i in xrange(2, n):

    s = abs(sum(a[:i]) - sum(a[i:]))

    if t > s:
        t = s

print t

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
an=list(map(int,input().split()))
l=[]
for i in range(1,N):
    x=sum(an[:i])
    y=sum(an[i:])
    l.append(abs(x-y))
print(min(l))

Submission status: Time Limit Exceeded

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

c = []
for i in range(N-1):
	b = a[0:i+1]
	c.append(abs(sum(a)-2*sum(b)))

print(min(c))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split(" ")]
a_sum = sum(a)
ans = 100000000000

for i in range(1,N):
    x = sum(a[0:i])
    y = a_sum - x
    tmp = abs(x-y)
    if ans >= tmp :
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Accepted

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

Submission status: Accepted

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

total = sum(main)
beg = 0
final = float('inf')
for i in range(len(main) - 1):
    beg += main[i]
    total -= main[i]
    final = min(final, abs(beg - total))

print(final)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))

a = np.array(a)
cum = np.cumsum(a)[:-1]
rcum = np.cumsum(a[::-1])[:-1]
ans = abs(cum - rcum[::-1])

print(np.min(ans))

Submission status: Accepted

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

s = A[0]
s_ = sum(A[1:])
gap = abs(s-s_)
for i in range(1, n-1):
    s += A[i]
    s_ -= A[i]
    if gap > abs(s-s_):
        gap = abs(s-s_)
print(gap)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 02:27:51 2020

@author: liang
"""

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
snuke=sum(a)
arai=0
ans=10**20
for i in range(n-1):
    snuke-=a[i]
    arai+=a[i]
    ans=min(ans,abs(snuke-arai))
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(y - x)
for i in range(1, N - 1):
    x += A[i]
    y -= A[i]
    ans = min(ans, abs(y - x))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
S1 = A[0]
S2 = sum(A)-A[0]
B = [abs(S1-S2)]

for i in range(N-2):
  S1 += A[i+1]
  S2 -= A[i+1]
  B.append(abs(S1-S2))

print(min(B))

Submission status: Accepted

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

s = sum(a)

x = a[0]
ans = abs(x - (s - x))
for i in a[1:-1]:
  ans = min(ans, abs(x - (s - x)))
  x += i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(min(B))

Submission status: Accepted

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

ans = []

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

for i in range(n-1):
  tmp = abs(a2[-1] - 2*a2[i])
  ans.append(tmp)
print(min(ans))

Submission status: Accepted

Solution code:
# C - Splitting Pile
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sum = sum(a)
    cnt = 0
    ans = float('inf')

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


if __name__ ==  "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
data = [a[0]]
m = abs(s - 2 * a[0])

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

for i in range(0, N - 1):
    if abs(s - 2 * data[i]) < m:
        m = abs(s - 2 * data[i])

print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))
bl = [0]*(n+1)
cl = [0]*(n-1)

for i in range(n):
    bl[i+1] = al[i] + bl[i]

for j in range(1, n):
    cl[j-1] = abs(bl[j] - (bl[n] - bl[j]))

print(min(cl))

Submission status: Accepted

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

Submission status: Accepted

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

sa = [0 for i in range(n)]
sc = sum(a)
c = 0
for i in range(n):
  c += a[i]
  sa[i] = c
ans = 10**10

for i in range(1,n):
  x = sc-sa[i-1]
  v = abs(x-sa[i-1])
  ans = min(ans,v)
print (ans)

Submission status: Accepted

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

    sum_a = sum(a)
    min_diff = 1000000000000000000000

    sum_x = 0
    for i in range(0, n-1):
        sum_x += a[i]
        diff = abs(sum_a - 2*sum_x)
        if min_diff > diff:
            min_diff = diff

    print(min_diff)

    '''
    half = sum_a // 2

    diff = []
    for i in range(n-1):
        diff.append(a[i+1] - a[i])
    min_diff = abs(min(diff))

    print(min_diff)
    '''

# 真ん中を分けるカードの差がわかればよい


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n_acc = itertools.accumulate(a)
#r_acc = itertools.accumulate(a[::-1])
# 1, 3, 6, 10, 15 ,21
# 1 vs 20
# 3 vs
#print(n_acc, r_acc)


sigma = sum(a)
ans = 10 ** 16

for i, val in enumerate(n_acc):
    if (i == len(a) - 1):
        break

    rest = sigma - val
    ans = min(abs(val - rest), ans)


print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
AA = list(accumulate([0] + A))
ans = 10 ** 20
for i in range(1, n):
    temp1 = AA[i]
    temp2 = AA[-1] - temp1
    delta = abs(temp1 - temp2)
    ans = min(delta, ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    x = a_lst[0]
    y = sum(a_lst) - x

    minimum = abs(x - y)
    for i in range(1, n - 1):
        a = a_lst[i]
        x += a
        y -= a
        minimum = min(minimum, abs(x - y))

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
  t-=2*a[i]
  if i==0:
    m=abs(t)
  else:
    m=min(abs(t),m)
print(m)

Submission status: Accepted

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

ans = float('inf')
arai = sum(A)
sunuke = 0
for i in range(n-1):
    sunuke += A[i]
    arai -= A[i]
    ans = min(ans, abs(sunuke-arai))

print(ans)

Submission status: Accepted

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    if i==0:
        m=abs(t)
    else:
        m=min(abs(t),m)
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
with open(0) as f:
    N, *a = map(int, f.read().split())
score = -sum(a[1:]) + a[0]
ans = abs(score)
for x in a[1:N-1]:
    score += 2*x
    ans = min(ans, abs(score))
print(ans)

Submission status: Accepted

Solution code:
with open(0) as f:
    N, *a = map(int, f.read().split())
score = -sum(a[1:]) + a[0]
ans = abs(score)
for x in a[1:N-1]:
    score += 2*x
    ans = min(ans, abs(score))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
nums = []
total = 0
for num in a:
    total += num
    nums.append(total)
minVal = 10 ** 9 * 2 + 1
for i in range(n - 1):
    sub = total - nums[i]
    minVal = min(abs(sub - nums[i]), minVal)
print(minVal)

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

ls_x = []
x = 0
for i in range(n):
    x += a[i]
    ls_x.append(x)    

S = sum(a)

m = INF
for i in range(n-1):
    x = ls_x[i]
    y = S - x
    m = min(m,abs(x-y))
print(m)

Submission status: Accepted

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

sunuke = [0] * (N)
guma = [0] * (N)

for i in range(N-1):
  if i == 0:
    sunuke[i] += A[i]
    continue  
  sunuke[i] += sunuke[i-1] + A[i]

for j in range(N-1,0,-1):
  if j == N - 1:
    guma[j] += A[j]
    continue
  guma[j] += guma[j+1] + A[j]
  
ans = float("inf")
for k in range(N-1):
  ans = min(ans, abs(sunuke[k] - guma[k+1]))

print(ans)

Submission status: Accepted

Solution code:
# C - Splitting Pile
N = int(input())
A = list(map(int,input().split()))

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

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

Submission status: Accepted

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

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sum(a) # sum a
cs = 0 # cards sunuke
arr = []

for i in range(n-1):
  cs += a[i]
  ca = sa -cs #cards araiguma
  arr.append(abs(cs-ca))
 
print(min(arr))

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 10**12
for i in range(1,n):
    snu = asum[i]
    arai = asum[-1] - asum[i]
    ans_ = abs(snu - arai)
    if ans >ans_:
        ans = ans_
        
print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
ans = INF
tmp = 0
S = sum(A)
for i in range(N-1):
    tmp += A[i]
    ans = min(ans,abs(S-2*tmp))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    n = i_input()
    a = i_list()

    total = sum(a)

    ans = INF
    trial = 0
    for i in a[:-1]:
        trial += i
        left = total - trial
        ans = min(ans,abs(trial-left))
    print(ans)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    sunuke = 0
    arai = sum(a)
    ans = float("inf")
    for i in range(n-1):
        sunuke += a[i]
        arai -= a[i]
        ans = min(ans,abs(sunuke-arai))

    print(ans)
main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

N=int(input())
A=list(map(int,input().split()))
total = sum(A)
arai = 0
sunuke = 0
ans = float('inf')

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
import math
sunuke = 0
kuma = sum(a)

memo = abs(2*a[0] - sum(a))
ans = abs(2*a[0] - sum(a))

for i in range(n):
    sunuke += a[i]
    kuma -= a[i]
    if abs(sunuke-kuma) > memo:
        ans = memo
    else:
        memo = abs(sunuke-kuma)

print(ans)

Submission status: Accepted

Solution code:
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


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

    ans = float("inf")
    S = sum(A)
    T = []
    T.append(A[0])
    for i in range(1, N-1):
        T.append(T[i-1]+A[i])
    for t in T:
        ans = min(ans, abs(S-2*t))

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


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

    ans = float("inf")
    S = sum(A)
    T = []
    T.append(A[0])
    for i in range(1, N):
        T.append(T[i-1]+A[i])

    if N == 2:
        ans = abs(A[0]-A[1])
    else:
        for i in range(1, N-1):
            ans = min(ans, abs(S-2*T[i]))
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

sunuke=0
araiguma=sum(a)

min_sa=100000000000000

for i in range(n-1):
    sunuke+=a[i]
    araiguma-=a[i]
    min_sa=min(min_sa,abs(araiguma-sunuke))
print(min_sa)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    from itertools import accumulate
    s = sum(a)
    return min(abs(s-2*aa) for aa in accumulate(a[:-1]))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
n = int(input())
#a, b = map(int,input().split())
al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

total = sum(al)
mn = abs(total-2*al[0])
x = 0
for i in range(1, n-1):
    x += al[i-1]
    y = total-x
    mn = min(mn, abs(x-y))

print(mn)

Submission status: Accepted

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

snuke = 0
bear = sum(a)
ans = float('inf')

for i in range(n-1):
    snuke += a[i]
    bear -= a[i]
    if abs(snuke - bear) < ans:
        ans = abs(snuke - bear)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x = a[0]
y = sum(a[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:
N = int(input())
lsa = list(map(int,input().split()))
sunu = lsa[0]
ara = sum(lsa)- lsa[0]
ans = abs(ara-sunu)
for i in range(1,N-1):
    sunu += lsa[i]
    ara -= lsa[i]
    ans = min(ans,abs(ara-sunu))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a = list(accumulate(a))
ans = 10**10
for i in range(n-1):
    ans = min(ans, abs(a[i]-a[-1]+a[i]))
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
b = [int(s) for s in input().split()]
su = sum(b) - b[a-1]
ar = b[a-1]
ans = abs(su - ar)

for i in range(2, a-1):
  su = su - b[a-i]
  ar = ar + b[a-i]
  tmp = abs(su - ar)
  if tmp < ans:
    ans = tmp
  tmp = 0

print(ans)

Submission status: Accepted

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

sum_A = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
    sum_A[i] = sum_A[i - 1] + A[i - 1]

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

Submission status: Accepted

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

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

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

ans = 10**9+1
for x in cum_sum[1:-1]:
    y = cum_sum[-1] - x
    ans = min(ans, abs(x-y))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
t=sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(a)
cnt = 0
for i in range(n - 1):
    cnt += a[i]
    rem = s - cnt
    l.append(abs(cnt - rem))
    
print(min(l))

Submission status: Accepted

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

Submission status: Accepted

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

cum_sum = 0
ans_lis = []
sumA = sum(A)
for i in range(0,N-1):
    cum_sum = cum_sum + A[i]
    score = abs(cum_sum - (sumA - cum_sum))

    ans_lis.append(score)

print(min(ans_lis))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    sum_sunuke = 0
    sum_arai = sum(A)
    diffs = []
    for i in range(N - 1):
        sum_sunuke += A[i]
        sum_arai -= A[i]
        diffs.append(abs(sum_sunuke - sum_arai))
    print(min(diffs))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int, input().split()))
sum1 = 0
sum2 = sum(arr)
min_ = 1<<60

for i in range(n-1):
    sum1 += arr[i]
    sum2 -= arr[i]
    min_ = min(min_, abs(sum1 - sum2))
print(min_)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
ans = 10**9*N
front = 0
back = sum(a)
for i in range(N-1):
    front += a[i]
    back -= a[i]
    ans = min(ans, abs(front-back))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

l = a[0]
r = sum(a)-l
ans = abs(l-r)

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

print(ans)

Submission status: Accepted

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

s = sum(a)
t = 0
minimum = math.inf
for i in range(N-1):
    t += a[i]
    s -= a[i]
    minimum = min(minimum,abs(s-t))
print(minimum)

Submission status: Accepted

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

S = sum(A)

snk = 0
arigm = S

ans = 1e20

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

Submission status: Accepted

Solution code:
n=int(input()) 
c=list(map(int, input().split()))
s = sum(c)
l = []
x = 0
y = s

for i in c[:n-1]:
    x += i
    y -= i
    l += [abs(x-y)]
print(min(l))

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, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

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

    t = list(accumulate(A, add))
    r = list(accumulate(reversed(A), add))

    ans = INF
    for i in range(N-2):
        ans = min(ans, abs(t[i] - r[-2-i]))

    print(ans)


if __name__ == '__main__':
    main()