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 = [int(i) for i in input().split()]
sunuke = a[0]
arai = sum(a[1:])
if N == 2:
    print(abs(a[0] - a[1]))
else:
    ans = float('inf')
    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())
a_lst = list(map(int, input().split()))

x = a_lst[0]
y = sum(a_lst[1:])
diff = abs(y - x)
for a in a_lst[1:-1]:
  x += a
  y -= a
  diff = min(diff, abs(y - x))
print(diff)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(x) for x in input().split()]
temp_list = [0] * n
temp_list[0] = a_list[0]
for i in range(1, n):
    temp_list[i] = a_list[i] + temp_list[i - 1]
ans = 10 ** 15
for i in range(n - 1):
    temp = abs(temp_list[-1] - (temp_list[i] << 1))
    if temp < ans:
        ans = temp
print(ans)

Submission status: Accepted

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

A_=[]
a_=0
for a in A:
    a_+=a
    A_.append(a_)

Z=A_[-1]
ans=10**20
for a_ in A_[:-1]:
    if ans > abs(Z-2*a_):
        ans = abs(Z-2*a_)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    sm = sum(a)
    xd = 0
    ans = float('inf')
    for i in range(n-1):
        xd += a[i]
        sm -= a[i]
        ans = min(ans, abs(xd - sm))
    print(ans)

        
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

7
3 1
4 1
5 9
2 6
5 3
5 8
9 7 5

"""

Submission status: Accepted

Solution code:
import numpy as np


def main():
    n = int(input())
    As = list(map(int, input().split()))
    cumsum = np.cumsum(As)
    ans = float("inf")
    for i in range(n-1):
        ans = min(ans, abs(cumsum[n-1]-2*cumsum[i]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
a = deque(list(map(int, input().split())))
ans = float('inf')
total = sum(a)
sm = 0
while len(a)>1:
    sm += a.pop()
    ans = min(abs(2*sm-total), ans)
print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
ans=10**100
b=sum(a)
c=0
for i in a[:-1]:
   c+=i
   b-=i
   ans=min(ans,abs(b-c))
print(ans)

Submission status: Accepted

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

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

    INF = 1 << 60
    a_sum = [0] * (N + 1)
    for i in range(N):
        a_sum[i + 1] = a_sum[i] + a[i]
    ans = INF
    for i in range(1,N):
        ans = min(ans, abs(a_sum[i] - (a_sum[N] - a_sum[i])))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

H = numpy.cumsum(a)[:-1]
S = sum(a) - H
print(min(abs(H - S)))

Submission status: Accepted

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

x = 0
ans = []
suma = sum(a)

for i in a[:-1]:
    x += i
    ans.append(abs(suma - x * 2))
else:
    print(min(ans))

Submission status: Accepted

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

x = 0
ans = []
suma = sum(a)

for i in range(n - 1):
    x += a[i]
    ans.append(abs(suma - x * 2))
else:
    print(min(ans))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())
a_li = list(map(int, input().split()))
# y = X - x
# |x - y| = |x - (X - x)|
#         = |-X + 2x|
total = sum(a_li)
acc = list(accumulate(a_li))
ans = 10 ** 18
for i in range(N - 1):
    ans = min(ans, abs(acc[i] * 2 - total))
print(ans)

Submission status: Accepted

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

snk = A[0]
arg = sum(A)-snk
ans = abs(arg-snk)
for i in range(1, N-1):
  snk += A[i]
  arg -= A[i]
  dif = abs(arg-snk)
  ans = min(ans, dif)
print(ans)

Submission status: Accepted

Solution code:
import itertools
def main():
    n=int(input())
    A=[int(i) for i in input().split()]
    rui = list(itertools.accumulate(A))
    mi = 300000000000
    ind = n-1

    for i in range(n-1):
        mi=min(abs(rui[i]-(rui[ind]-rui[i])),mi)

    print(mi)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = sum(a)
x = a[0]
res = abs(s - 2 * x)
for i in range(1, N - 1):
    x += a[i]
    y = s - x
    if res > abs(y - x):
        res = abs(y - x)
print(res)

Submission status: Accepted

Solution code:
def INT():
    return int(input())

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

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

N = INT()
a = LI()

x = a[0]
y = sum(a) - x

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


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

Submission status: Accepted

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

x=sum(A)
y=0
ans=10**16

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

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
lis = list(map(int, input().split()))
k = list(itertools.accumulate(lis))
x = sum(lis)

ans = 100100100100100100

for i in range(n-1):
    t = k[i]
    t2 = x - t
    
    ans = min(ans, abs(t-t2))

print(ans)

Submission status: Accepted

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

for i in range(1,n):
    l[i] = l[i-1] + a[i]
sum = sum(a)
ans = 10**10+1
for i in range(len(l)-1):
    x = l[i]
    y = sum - l[i]
    tmp = abs(x-y)
    ans = min(ans,tmp)

print(ans)

Submission status: Accepted

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

sm = []
tmp = 0
for a in As:
  tmp += a
  sm.append(tmp)
  
rlt = sum(map(abs, As))
for i in range(N-1):
  rlt = min(rlt, abs(2*sm[i]-sm[-1]))
  
print(rlt)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
summ = sum(a)
ruisekiwa = []
tmp = 0
for i in range(n):
    tmp += a[i]
    ruisekiwa.append(tmp)
ans = 100100100100
for i in range(len(ruisekiwa) - 1):
    ans = min(ans, abs(ruisekiwa[i] - (summ - ruisekiwa[i])))
print(ans)
# print(ruisekiwa)

Submission status: Accepted

Solution code:
import sys
import itertools

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = rl()
s = sum(a)
t = list(itertools.accumulate(a))
min_ = inf
for i in range(n-1):
    x = t[i]
    min_ = min(min_, abs((s-x) - x))
print(min_)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
nums=sum(a)-a[0]
numa=a[0]
def ab(num1,num2):
    return abs(num1-num2)
ans=ab(nums,numa)
for i in range(n-2):
    nums-=a[i+1]
    numa+=a[i+1]
    ans=min(ans,ab(nums,numa))
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    x = 0
    y = sum(a)
    m = 10**100
    for i in range(N-1):
        x += a[i]
        y -= a[i]
        m = min(m, abs(x-y))
    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
aa=sum(a)-a[0]
tmp=a[0]
t=abs(tmp-aa)
ans=float("inf")
if ans>t:
    ans=t
for i in range(1,n-1):
    tmp+=a[i]
    aa-=a[i]
    t=abs(tmp-aa)
    if ans>t:
        ans=t
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
for i in range(1, n):
  lst[i] += lst[i - 1]
z = lst[-1]
res = 10 ** 20
for i in range(n - 1):
  res = min(res, abs(lst[i] - (z - lst[i])))
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from numpy import cumsum
left_cumsum=cumsum(a)
a.reverse()
right_cumsum=cumsum(a)
ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_cumsum[i]-right_cumsum[-i-2]))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
def main():
    N = int(input())
    a = list(map(int, input().split()))
    AC = list(itertools.accumulate(a))
    M = sum(a)
    ans = abs(M - a[0]*2)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

result = 10**10
for i in range(1,n):
  snuke = s[i]
  arai = s[n] - s[i]
  result = min(result, abs(snuke-arai))
print(result)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
arai=sum(A)
ans=10**19
sunuke=0
for a in range(N-1):
  sunuke+=A[a]
  arai-=A[a]
  if ans>abs(arai-sunuke):
    ans=abs(arai-sunuke)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count=[[]for _ in range(N-1)]
count[0]=[A[0],S-A[0]]
i=1
while i<N-1:
    count[i]=[A[i]+count[i-1][0],S-(A[i]+count[i-1][0])]
    i+=1

print(min(abs(l-r) for l,r in count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(a)
t = 0
ans = float("inf")

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

Submission status: Accepted

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

y=sum(a)
x=0
mn=10**18
for i in range(n-1):
    x+=a[i]
    y-=a[i]
    mn=min(mn, abs(x-y))

print(mn)

Submission status: Accepted

Solution code:
n,*a = map(int,open(0).read().split())
total = sum(a)
ans = 10**18
dt = 0
for i in range(n-1):
  dt += a[i]
  ans = min(ans,abs(total-dt-dt))
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
cumsum_a = a.cumsum()
sum_a = cumsum_a[-1]
ans = 2 * 10**9

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a1 = [0]
for i in range(n):
    a1.append(a1[-1]+a[i])
def sumArea(l,r):
    return a1[r] - a1[l]

ans = inf
for i in range(1,n):
    ans = min(ans,abs(sumArea(0,i)-sumArea(i,n)))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from itertools import accumulate
ac = [0] + list(accumulate(A))

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0]*(N+1)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 10 ** 15
now = 0
for i in range(N):
  now += A[i]
  if (i != N - 1):
    ans = min(ans, abs(m - 2 * now))

print(ans)

Submission status: Accepted

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

sunuke = A_s[0]
kuma = sum(A_s[1:])
mini = abs(sunuke - kuma)


for i in range(1, N - 1):
    sunuke += A_s[i]
    kuma -= A_s[i]
    
    mini = min(mini, abs(sunuke - kuma))

print(mini)

Submission status: Accepted

Solution code:
N=int(input())
a=input().split()
a=[int(b) for b in a]
numbers=[]
number=0
for a_ in a:
    number+=a_
    numbers.append(number)
del numbers[-1]
if N==2:
    print(abs(a[0]-a[1]))
else:
    whole=sum(a)
    answers=[]
    for number in numbers:
        answer=abs(number*2-whole)
        answers.append(answer)
    print(min(answers))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = float("inf")
x = 0
y = sum(a)
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:
# https://atcoder.jp/contests/abc067/tasks/arc078_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


INF = 10 ** 15

N = a_int()
A = ints()

# 山札の上から取るから位置を全探索可能
x = 0  # すぬけくんのカードの合計
y = sum(A)
ans = INF
for a in A[:-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()))

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc067/tasks/arc078_a

n = int(input())
nums = [int(i) for i in input().split()]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

N = int(input())
A = list(map(int,input().split()))
total = sum(A)
ACC = list(itertools.accumulate(A))

ans = 10 ** 10
for i in range(N-1):
  x = ACC[i]
  y = total - x
  ans = min(ans,abs(x - y))

print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
ans = float('inf')
sums = [a[0]]
for i in range(1, n):
    sums.append(sums[-1] + a[i])

for i in range(n - 1):
    x = sums[i]
    y = sums[-1] - sums[i]
    # print(f'{x=}, {y=}')
    ans = min(ans, abs(x - y))
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
N = I()
A = readInts()
sumA = sum(A)
MIN = float('inf')
snuke = 0
for i in range(N-1):
    snuke += A[i]
    sumA -= A[i]
    MIN = min(MIN,abs(snuke - sumA))
print(MIN)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
input()
cards = tuple(map(int, input().split(' ')))

a = sum(cards[1:])
s = cards[0]
diff_min = abs(a - s)

for card in cards[1:-1]:
    a -= card
    s += card
    diff_min = min(diff_min, abs(a - s))

print(diff_min)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))

    ans = INF
    snuke = 0
    arai_san = sum(a)

    for x in a[:-1]:
        snuke += x
        arai_san -= x
        ans = min(ans, abs(snuke - arai_san))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int , input().split()))
total = sum(a)
s = 0
ans = 10**10

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

print(ans)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    SM = sum(A)
    for n in range(N - 1):
        A[n + 1] += A[n]

    ret = MAX
    for n in range(N-1):
        ret = min(ret, abs(SM - 2 * A[n]))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
D=[]
goukei=0

for i in range(N):
    goukei+=S[i]
    D.append(goukei)

T=[]    
for i in range(N-1):
    T.append(abs((goukei-D[i])-D[i]))
    
print(min(T))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N =ii()
    A = il()
    sm = sum(A)
    for n in range(N-1):
        A[n+1] += A[n]

    ret = MAX
    for n in range(N-1):
        ret = min(ret, abs(-sm+(2*A[n])))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    R = [A[0]]
    for i in range(1, N):
        R.append(R[-1]+A[i])
    ans = 2*(10**9)
    for i in range(N-1):
        x = R[i]
        y = R[N-1] - R[i]
        ans = min(ans, abs(x-y))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
s,temp = [],0
for i in range(n):
    temp += a[i]
    s.append(temp)
sn,mi = s[n-1],2000000001
for i in range(n-1):
    snuke = s[i]
    arai = sn-s[i]
    if abs(snuke-arai)<mi:
        mi = abs(snuke-arai)
print(mi)

Submission status: Accepted

Solution code:
from numpy import cumsum

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

ans = 1000000000000000000
ruiseki = cumsum(a)
sum = ruiseki[len(ruiseki)-1]
for i in range(len(ruiseki)-1):
    x = ruiseki[i]
    y = sum - ruiseki[i]
    ans = min(ans, abs(x-y))

print(ans)

Submission status: Accepted

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

l = sum(a)
r = 0
ans = 10**20

for i in a[:-1]:
    l -= i
    r += i
    ans = min(ans, abs(l - r))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
cumsum = np.cumsum(a)
s = cumsum[-1]
m = float('inf')
for i in range(n - 1):
    t = cumsum[i]
    m = min(m, abs(2 * t - s))
print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
limit = 10**9 + 10**9
b = 0
for i in a[:-1]:
    b += i + i
    diff = abs(total - b)
    if limit > diff:
        limit = diff
print(limit)

Submission status: Accepted

Solution code:
n = int(input())
ls = list(map(int,input().split()))
mx = sum(ls)
a = 0
k = float("inf")
for i in range(n-1):
    a += ls[i]
    if k > abs(mx-a*2):
        k = abs(mx -a*2)
print(k)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import accumulate
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    s1=list(accumulate(a))
    s2=list(accumulate(reversed(a)))

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

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

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

import numpy as np
sumA = np.cumsum(A)

ans = float('inf')
for i in range(0, N-1):
    x = sumA[i]
    y = sumA[-1] - x
    ans = min(abs(x-y), ans)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

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

su = a[0]
if n == 2:
  ar = a[1]
else:
  ar = sum(a[1:n])
dif = su-ar
mi = abs(dif)
for i in range(1,n-1):
  dif = dif+2*a[i]
  abs_dif = abs(dif)
  if mi > abs_dif:
    mi = abs_dif
print(mi)

Submission status: Accepted

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

rusekiwa = [al[0]]

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

#print(rusekiwa)
lst = []
for n in range(0,N-1):
    x = rusekiwa[n]
    y = rusekiwa[-1] - rusekiwa[n]
    lst.append(abs(x - y))
#print(lst)
print(min(lst))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
tmp = list(accumulate(A))[:len(A)-1]
total  = sum(A)

    
ans = min([abs(total-2*a) for a in tmp])
print(ans)