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:
def splitting_pile(N: int, A: list)->int:
    snuke, raccoon = A[0], sum(A[1:])

    min_diff = abs(snuke-raccoon)
    for a in A[1:-1]:
        snuke += a
        raccoon -= a
        min_diff = min(min_diff, abs(snuke-raccoon))

    return min_diff


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = splitting_pile(N, A)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

sumA = A.sum()

print(np.abs(2*np.cumsum(A) - sumA)[:-1].min())

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 10e9
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:
import sys

N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=sys.maxsize

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

for i in range(1,N):
  x = L[i]
  y = L[-1] - L[i]
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import numpy
res = numpy.cumsum(A)
sum_A = sum(A)

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

Submission status: Accepted

Solution code:
n=int(input())

A=list(map(int,input().split()))
sa=sum(A)
S=[]
for i in range(0,n-1):
    sa-=2*A[i]
    S.append(abs(sa))
print(min(S))

Submission status: Accepted

Solution code:
n=int(input())

A=list(map(int,input().split()))
sa=sum(A)-2*A[0]
S=[abs(sa)]
if n>2:
    for i in range(1,n-1):
        sa-=2*A[i]
        S.append(abs(sa))
    print(min(S))
         
else:
    a=A[0]
    b=A[1]
    print(abs(a-b))

Submission status: Accepted

Solution code:
N = int(input())
a =[int(_) for _ in input().split()]
ans = 10**15
cardsum = sum(a)
ruiseki = [0]

for i in range(N-1):
    ruiseki.append(ruiseki[i]+a[i])
    snuke = ruiseki[i+1]
    arai = cardsum - snuke
    diff = abs(snuke - arai)
    if diff < ans:
        ans = diff

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
ans = 100000000000
SUM = sum(a)
for i in b[:-1]:
  tmp = abs(SUM - i * 2)
  if tmp < ans:
    ans = tmp
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
su=sum(l)
l.pop()
a=0
x=99999999999999999999
for i in l:
  a+=i
  b=su-a
  c=abs(a-b)
  if c<x:
    x=c
print(x)

Submission status: Accepted

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

A_sum = sum(A)
check = 0
ans = 10 ** 18
for i in range(N-1):
    check += A[i]
    ans = min(abs(check - (A_sum - check)), ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1,n-1):
    x += a[i]
    y -= a[i]
    diff =  abs(x-y)
    if min_diff > diff:
        min_diff = diff

print(min_diff)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
S = sum(A)
res = []
Sa = 0
for a in A[:-1]:
        Sa += a
        res.append(abs(2*Sa-S))

print(min(res))

Submission status: Accepted

Solution code:
n = int(input())

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

sm = sum(li_a)

li_ruiseki = list()

for a in li_a:
    if len(li_ruiseki) == 0:
        li_ruiseki.append(a)
    else:
        li_ruiseki.append(li_ruiseki[-1] + a)

result = -1
for x in li_ruiseki[:-1]:
    a = abs(sm - 2 * x)
    result = min(result, a) if result >= 0 else a

print(result)

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]

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

print( ans )

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
lst=[int(i) for i in input().split()]
import numpy
res=numpy.cumsum(lst)
ans=10e20
for i in range(N-1):
  ans=min(ans,abs(res[i]-(res[-1]-res[i])))
print(ans)

Submission status: Accepted

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

max_ = sum(A)
tmp = 0
result = []
for i in range(N-1):
  tmp += A[i]
  result.append(abs(max_-2*tmp))
print(min(result))

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

# 二分探索 #
def nibutan(list,n):
	left = 0
	right = len(list)
	while left+1 != right:
		middle = (left+right)//2
		if list[middle] <= n:
			left = middle
		else:
			right = middle
	return right

N = I()
l = IL()
tmp = l[0]

suml = [tmp]
for i in range(1,N):
	tmp += l[i]
	suml.append(tmp)

num = suml[0]
ans = abs(suml[-1]-num*2)
for i in range(1,N-1):
	num = suml[i]
	ans = min(ans, abs( suml[-1] - num*2 ))

print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n = I()
a = LI()
b = [None for i in range(n-1)]
for i in range(n-1):
    a[i+1] += a[i]
for i in range(n-1):
    b[i] = abs(2*a[i]-a[n-1])
print(min(b))
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
#ABC067C
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()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    s = sum(a)
    x = 0
    m = float('inf')

    for i in a[:-1]:
        x += i
        y = s - x
        m = min(m, abs(x - y))
    
    return m

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

z=sum(a)

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

Submission status: Accepted

Solution code:
n = int(input())

X = list(map(int, input().split()))
ans = 1000000000000000000
before = 0
after = sum(X)
X = X[:-1]
for i in X:
    before += i
    after -= i
    num = abs(before - after)
    ans  = min(ans, num)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
accum = [0 for i in range(N+10)]
L_sum = sum(L)
ans = 10**100
for i in range(len(L)):
    accum[i+1] = accum[i] + L[i]
for i in range(1,len(L)):
  #  print(accum[i],L_sum-accum[i])
    ans = min(ans,abs(2*accum[i]-L_sum))
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
n=int(input())
A=list(map(int,input().split()))
S=list(accumulate(A))
ans=float('inf')
for i in range(n-1):
    ans=min(ans,abs(S[-1]-S[i]*2))
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A_total[0] = A[0]

for i in range(1,len(A)):
    A_total[i] = A_total[i-1] + A[i]

min_num = float('inf')

for i in range(len(A_total[:-1])):
    snuke = A_total[i]
    bear = A_total[-1] - A_total[i]
    tmp = abs(snuke-bear)
    if min_num > tmp:
        min_num = tmp

print(min_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

ans = 10**100
res = np.cumsum(a)

print(min([abs(res[-1]-res[i]-res[i]) for i in range(len(res)-1)]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()
snuke = sum(a[:-1])
arai = a[-1]
ans = abs(snuke-arai)
for i in range(2, n):
    debug(a[-i])
    snuke -= a[-i]
    arai += a[-i]
    ans = min(abs(snuke - arai), ans)
    
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a))

Submission status: Accepted

Solution code:
def solve(N, As):
    d = 0
    s = sum(As)
    m = 10 ** 15
    for a in As[:N - 1]:
        d += a
        m = min(m, abs(d - (s - d)))
    return abs(m)


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

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

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

ans = []
for i in range(0, N - 1):
    ans.append(abs(X - 2*b[i]))

print(min(ans))

Submission status: Accepted

Solution code:
n = int(input())
*a, = map(int, input().split())
Table = [0, sum(a)]
ans = float("inf")

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp = 0
ans = 10 ** 10
for i in range(n - 1):
    tmp += A[i]
    ans = min(ans, abs(tmp -(sumA - tmp)))
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(N - 1):
    diff = abs(subtotals[-1] - 2*subtotals[i])
    ans = diff if i == 0 else min(ans, diff)

print(ans)

Submission status: Accepted

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

acc = list(accumulate(a))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
x = 0
s = sum(A)
ab = -1
for i in range(n-1):
    a = A[i]
    x += a
    if ab == -1:
        ab = abs(s - 2*x)
    else:
        ab = min(ab, abs(s - 2*x))
print(ab)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
l = list(map(int, input().split()))
nl = np.array(l)
X = nl.sum()
a = []
x = 0
for i in range(N-1):
    x = x + nl[i]
    a.append(abs(2 * x - X))
print(min(a))

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a = [int(i) for i in input().split()]
ala = sum(a)
tmp = 0
ans = np.array([9999999999]*n)

for i in range(n-1):
 tmp += a[i]
 ala = ala - a[i]
 ans[i] = abs(tmp-ala)
print (min(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum_ls = [a[0]]
for i in range(1,n):
    sum_ls.append(sum_ls[i-1]+a[i])
check = sum_ls[n-1];ans = abs((check-sum_ls[0])-sum_ls[0])
for i in range(1,n-1):
    ans = min(ans,abs((check-sum_ls[i])-sum_ls[i]))
print(ans)

Submission status: Accepted

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

x = a[0]
y = sum(a[1:])

ans = abs(x-y)

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

print(ans)

Submission status: Accepted

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

A_r = A[::-1]

cumsum_A = np.cumsum(A)
cumsum_A_r = np.cumsum(A_r)

x = [abs(a - a_r) for (a, a_r) in zip(cumsum_A[:-1], cumsum_A_r[-2::-1])]
print(min(x))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
#print(minans)

mydata=0
for i in range(0,n-1):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int,input().split()))
mins = 10**10
csum = [0 for _ in range(N)]
csum[0] = arr[0]
for i in range(1,N):
    csum[i] = csum[i-1] + arr[i]    
for i in range(N-1):
    cards = abs(csum[N-1]-2*csum[i])
    if cards < mins:
        mins = cards
print(mins)

Submission status: Accepted

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

l=[0]
def ruiseki(a):
    for i in range(n):
        l.append(l[i]+a[i])
    del l[0]

ans=100000000000000
ruiseki(a)
x=0
y=0

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

print(ans)

Submission status: Accepted

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

sunuke = 0
arai = sum(a)
ans = float('inf')

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
r = [0]*n
ans = float('Inf')

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

print(ans)

Submission status: Accepted

Solution code:
def abc067_c():
    n = int(input())
    a = list(map(int, input().split()))
    x = a[0]
    y = sum(a[1:])
    del a[0]
    del a[-1]
    diff = abs(x - y)
    for v in a:
        x += v
        y -= v
        if abs(x - y) < diff:
            diff = abs(x - y)
    print(diff)


abc067_c()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
    
A = a[0]
B = sum(a[1:])

min = abs(A - B)

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

    if min > abs(A - B):
        min = abs(A - B)


print(min)

Submission status: Accepted

Solution code:
#067-C
n=int(input())
a=list(map(int,input().split()))
sa=[a[0] for i in range(n)]
for i in range(1,n):
    sa[i]=sa[i-1]+a[i]
mm=float("INF")
for i in range(n-1):
    mm=min(mm,abs(sa[i]-(sa[n-1]-sa[i])))
print(int(mm))

Submission status: Accepted

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

x = 0
y = sum(a)
cand = []
for e in a[:N-1]:
    x += e
    y -= e
    cand.append(abs(x-y))
print(min(cand))

Submission status: Accepted

Solution code:
n = int(input().strip())
a = list(map(int, input().strip().split()))
x, y = a[0], sum(a[1:])
minxy = abs(x-y)

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

print(minxy)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    aa = list(map(int, input().split()))
    x = aa[0]
    y = sum(aa[1:])
    res = abs(x - y)
    for a in aa[1:-1]:
        x += a
        y -= a
        res = min(res, abs(x - y))
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

total = sum(A)

result = 10**100
x = 0
for a in A[:-1]:
    x += a
    r = abs(total - x - x)
    result = min(result, r)

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(a)

ans = float('inf')
x = 0
for i in range(n-1):
    x += a[i]
    ans = min(ans, abs(s-2*x))

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
B=[A[0]]
for j in range(1,N):
    B.append(B[j-1]+A[j])
#print(B)

ans=10000000000
for i in range(N-1):
    ans=min(abs((S-B[i])-B[i]),ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = float('inf')
for a in A[:-1]:
    S -= 2 * a
    if abs(S) < ans:
        ans = abs(S)
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]

ans = float('inf')

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
number=list(map(int,input().split()))
Sum=sum(number)
number_sum=[0]*N
number_sum[0]=number[0]
result=[0]*(N-1)
for i in range(1,N):
  number_sum[i]=number_sum[i-1]+number[i]
result[0]=abs(number_sum[0]*2-Sum)
for i in range(1,N-1):
  result[i]=abs(((number_sum[i])*2-Sum))

print(min(result))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
snk = a[0]
ans = abs(total - 2*snk)
for i in range(1,n-1):
    snk += a[i]
    if ans > abs(total - 2*snk):
        ans = abs(total - 2*snk)
print(ans)

Submission status: Accepted

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

x = a[0]
y = sum(a[1:])
diff = abs(x - y)

for i in a[1:-1]:
    x += i
    y -= i
    diff = min(diff, abs(x - y))

print(diff)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
sum=[0,]*n
sum[0]=a[0]
min=5000000000
for i in range(1,n):
    sum[i]=a[i]+sum[i-1]
fin=sum[n-1]
sub=[0,]*n
for i in range(0,n):
    sub[i]=fin-sum[i]
for i in range(0,n-1):
    if abs(sub[i]-sum[i]) < min:
        min = abs(sub[i]-sum[i])
print(str(min))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
tmp=[]
all_sum=sum(a)
tmp_sum=0
tmp_sum2=all_sum
for i in range(n-1):
    tmp_sum+=a[i]
    tmp_sum2-=a[i]
    tmp.append(abs(tmp_sum-tmp_sum2))
print(min(tmp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input().strip())
al = list(map(int,input().strip().split(" ")))

pos = 1 #アライグマのとる最初のcardのindex

diff = 1000000000
asum = sum(al)
tmp_sum = 0

diff = []
for a in al[:-1]:
    tmp_sum += a
    diff.append(abs(asum - tmp_sum * 2))

print(min(diff))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]+[0]
sumsub = A[0]
sumall = sum(A)
ans = abs(2*sumsub-sumall)
for i in range(1, N-1):
    sumsub += A[i]
    ans = min(ans, abs(2*sumsub-sumall))
print(ans)

Submission status: Accepted

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

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

print(score)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
imos = [a[i] for i in range(n)]
for i in range(1, n):
    imos[i] += imos[i - 1]
diff = abs(imos[-1] - 2 * a[0])
for i in range(1, n-1):
    diff = min(diff, abs(imos[-1] - 2 * imos[i]))
print(diff)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a = [int(m) for m in a]
xyli = []
for i in range(n - 1):
    if i == 0:
        snu = a[i]
        ara = sum(a) - a[i]
        xyli.append(abs(snu - ara))
    else:
        snu += a[i]
        ara -= a[i]
        xyli.append(abs(snu - ara))
print(min(xyli))

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a1_list = a_list
res_list =[]
a_score = 0
s_score = 0
for i in range(n):
    a_score += a_list[i]    
for i in a1_list:
    a_score -= i
    s_score += i
    res = abs(s_score - a_score)
    res_list.append(res)
del res_list[n-1]
print(min(res_list))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
X = 0
Y = sum(A)
ans = float('inf')
for i in range(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())
l=list(map(int,input().split()))
s=[]
a=l[0]
b=-l[0]
for i in l:
    b+=i
c=a-b
s=[abs(c)]
for i in range(1,n-1):
    c+=2*l[i]
    s.append(abs(c))
print(min(s))

Submission status: Accepted

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

sum = 0
for a in A:
    sum += a
x = A[0]
y = sum - A[0]
min_num = abs(x-y)

for i in range(1, len(A)-1):
    x = x + A[i]
    y = y - A[i]
    n = abs(x-y)
    if n < min_num:
        min_num = n
print(min_num)

Submission status: Accepted

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

Submission status: Accepted

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

r = []

ruiseki = 0
for val in a:
    ruiseki += val
    r.append(ruiseki)

ans = 999999999999
for i in range(N-1):
    if ans > abs(r[-1] - r[i] - r[i]):
        ans = abs(r[-1] - r[i] - r[i])
print(ans)

Submission status: Accepted

Solution code:
# encoding: utf-8
N = int(input())
a = list(map(int, input().split()))

a_sum = [0] * N
tmp = 0
for i, ai in enumerate(a):
    tmp += ai
    a_sum[i] = tmp

def diff(A, B): return A - B if A > B else B - A
    
ans = 0
ans_diff = diff(a_sum[0], a_sum[-1] - a_sum[0])
for tmp in range(1, N - 1):
    tmp_diff = diff(a_sum[tmp], a_sum[-1] - a_sum[tmp])
    if tmp_diff < ans_diff: ans, ans_diff = (tmp, tmp_diff)

print(ans_diff)

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
count = 0
mc = 0
for r in ar:
    mc += r
br = []
for i in range(a-1):
    count += ar[i]
    br.append(abs((mc - count) - count))
print(min(br))

Submission status: Accepted

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

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans > abs(p-q) :
            ans = abs(p-q)
        
print(ans)

Submission status: Accepted

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