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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n = int(input())
l = list(map(int,input().split()))
s = sum(l)
l1 = list(accumulate(l))
l2 = [abs(2*i-s) for i in l1]
print(min(l2))

Submission status: Wrong Answer

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  
  A = sorted(A)
  sumA = sum(A)
  div = sumA / 2
  
  ANS = [0] * (n+1)
  sign = 1
  ANS[0] = A[0]
  i = 1
  while i < n:
    if i < n:
      if ANS[i-1] + A[i] >= div:
        sign = -1
    
    ANS[i] = ANS[i-1] + A[i]*sign
    i += 1
    
    #print(i,ANS[i-1])
  print(abs(ANS[n-1]))
  
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  
  A = sorted(A)
  sumA = sum(A)
  div = sumA / 2
  
  LE = [0] * (n+1)
  RI = [0] * (n+1)
  i = 0
  LE[0] = A[0]
  while LE[i] + A[i+1] < div:
    LE[i+1] = LE[i] + A[i+1]
    i += 1
  LEidx = i
  i += 1
  #print(A[i])
  RI[i] = A[i]
  while i != n - 1:
    #print(A[i+1])
    RI[i+1] = RI[i] + A[i+1]
    i += 1
    #print(RI[i])
  
  print(abs(LE[LEidx] - RI[i]))
  
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
ans = abs(sum(A)-2*A[0])
val=[]

for k in range(0,N-1):
  ans = abs(ans-2*A[k+1])
  val.append(ans)

print(min(val))

Submission status: Wrong Answer

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

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 2*(10**5)
    
#     if N == 2:
#         return abs(arr[0]- arr[1])
    
    for i in range(N-1):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)
#         print("sunuke: {}".format(sum_sunuke))
#         print("arai: {}".format(sum_arai))
        if min_val > val:
            min_val = val
#             print("min val: {}".format(min_val))
#         print("*************")
    return min_val

print(main(a_arr))

Submission status: Wrong Answer

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

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 2*(10**5)
    
    if N == 2:
        return abs(arr[0]- arr[1])
    
    for i in range(N-1):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)
#         print("sunuke: {}".format(sum_sunuke))
#         print("arai: {}".format(sum_arai))
        if min_val > val:
            min_val = val
#             print("min val: {}".format(min_val))
    return min_val

print(main(a_arr))

Submission status: Wrong Answer

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

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 2*(10**5)
    
    if N == 2:
        return abs(arr[0]- arr[1])
    
    for i in range(N):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)
#         print("sunuke: {}".format(sum_sunuke))
#         print("arai: {}".format(sum_arai))
        if min_val > val:
            min_val = val
#             print("min val: {}".format(min_val))
    return min_val

print(main(a_arr))

Submission status: Wrong Answer

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

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 2*(10**5)
    for i in range(1,N):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)
        # print(sum_sunuke)
        if min_val > val:
            min_val = val
    return min_val

print(main(a_arr))

Submission status: Wrong Answer

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

def main(arr):
    sum_sunuke = 0
    sum_arai      = sum(arr)
    min_val = 2*(10**5)
    for i in range(1,N):
        sum_sunuke += arr[i]
        sum_arai      -= arr[i]
        val = abs(sum_sunuke - sum_arai)
        print(sum_sunuke)
        if min_val > val:
            min_val = val
    return min_val

print(main(a_arr))

Submission status: Wrong Answer

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

A_sum = sum(A)
ans = []

for k in range(1,N//2+1):
  S = sum(A[:k])
  T = A_sum-S
  ans.append(abs(S-T))

print(min(ans))

Submission status: Wrong Answer

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

ans = []

for k in range(N):
  S = sum(A[:k])
  T = sum(A[k:])
  ans.append(abs(S-T))

print(min(ans))

Submission status: Wrong Answer

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

sub = sum(a)
s = 0
ans = (10 ** 9) + 100
for i in range(n):
    s += a[i]
    if (i + 1) < n:
        ans = min(ans, abs(sub - (2 * s)))

print(ans)

Submission status: Wrong Answer

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

sub = sum(a)
s = 0
ans = 10 ** 9
for i in range(n):
    s += a[i]
    if i + 1 < n:
        ans = min(ans, abs(sub - 2 * s))

print(ans)

Submission status: Wrong Answer

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

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

ans = 10 ** 9
for i in range(1, n):
    snuk = ruiseki[i] - ruiseki[0]
    arai = ruiseki[n] - ruiseki[i]
    ans = min(ans, abs(snuk - arai))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = abs(a[0]-a[-1])
max_ans = sum(a)
sumu = a[0]
for i in range(1,n-1):
  sumu += a[i]
  arai = max_ans - sumu
  kari = abs(sumu-arai)
  if kari < ans:
    ans = kari
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
x,y = A[0],A[1]
for i in range(2,N):
    a = A[i]
    if a>=0:
        if x<=y:x+=a
        else:y+=a
    else:
        if x<=y:y+=a
        else:x+=a
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
x,y = 0,0
for a in A:
    if a>=0:
        if x<=y:x+=a
        else:y+=a
    else:
        if x<=y:y+=a
        else:x+=a
print(abs(x-y))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
x,y = 0,0
for a in A:
    if x<=y:
        x+=a
    else:
        y+=a
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
v.sort()
a = 1000000007
s = 0
for i in range(0, len(v)):
  s += v[i]
  a = min(a, abs(v[i]))
print(2*a-s%2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
work = [0 for i in range(n)]
temp = 0
i = 0
for el in a:
    temp += el
    work[i] = temp
    i += 1
work = sorted([abs(temp-2*x) for x in work[:-1]])
print(work[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
total = sum(a_list) 
x_list = [0 for i in range(n-1)]
for i in range(1, n):
	x_list[i-1] = sum(a_list[0:i])
print(x_list)
y_list = [0 for i in range(n-1)]
for i, x in enumerate(x_list):
	y_list[i] = abs(total - x*2)
print(min(y_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
index = n // 2
index -= 1
diff = 2*10**5
while True:
	f_list = a_list[0:index]
	b_list = a_list[index:n]
	if len(f_list) == 0 or len(b_list) == 0:
		index += 1
		continue
	total_1 = sum(f_list)
	total_2 = sum(b_list)
	tmp_diff = abs(total_1 - total_2)
	if diff < tmp_diff:
		break
	diff = tmp_diff
	index += 1
	if index >= n:
		break
print(diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
count = len(a_list)
index = count // 2
index -= 1
diff = 2*10**5
while True:
	f_list = a_list[0:index]
	b_list = a_list[index:count]
	if len(f_list) == 0 or len(b_list) == 0:
		index += 1
		continue
	total_1 = sum(f_list)
	total_2 = sum(b_list)
	tmp_diff = abs(total_1 - total_2)
	if diff < tmp_diff:
		break
	diff = tmp_diff
	index += 1
	if index >= count:
		break
print(diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0
L.sort()
if n == 2:
    print(abs(L[1]-L[0]))
    exit ()
ans = 10**20
for i in range(n-1):
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    #print(sa,sum1-sum2,sum2)
    ans = min(ans,sa)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0
L.sort()
if n == 2:
    print(abs(L[1]-L[0]))
    exit ()

for i in range(n):
    ans = 10**20
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    #print(sa,sum1-sum2,sum2)
    ans = min(ans,sa)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0
L.sort()
if n == 2:
    print(abs(L[1]-L[0]))
    exit ()
ans = 10**20
for i in range(n):
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    #print(sa,sum1-sum2,sum2)
    ans = min(ans,sa)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
sum1 = sum(L)
sum2 = 0
L.sort()
ans = 10**20
for i in range(n-1):
    sum2 +=L[i]
    sa = abs(sum1 - sum2- sum2)
    #print(sa)
    ans = min(ans,sa)
print(ans)

Submission status: Wrong Answer

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

if n==2:
    print(abs(a[1]-a[0]))
else:
    asum=sum(a)
    xsum=0
    xmin=n*(10**9)
    for i in range(n):
        xsum=xsum+a[i]
        xmin=min(xmin,abs(asum-2*xsum))
    print(xmin)

Submission status: Wrong Answer

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

if n==2:
    print(abs(a[1]-a[0]))
else:
    d=[]
    a.sort()
    if n%2==0:
        for i in range(0,n-1,2):
            d.append([a[i+1]-a[i],i])
        d.sort(reverse=True)
        snk=a[d[0][1]]
        arg=a[d[0][1]+1]
        for i in range(2,len(d)-1):
            if snk>=arg:
                arg=arg+a[d[0][1]+1]-a[d[0][1]]
            else:
                snk=snk+a[d[0][1]+1]-a[d[0][1]]
    else:
        for i in range(0,n-2,2):
            d.append([a[i+1]-a[i],i])
        d.sort(reverse=True)
        snk=a[n-1]
        arg=0
        for i in range(2,len(d)-1):
            if snk>=arg:
                arg=arg+a[d[0][1]+1]-a[d[0][1]]
            else:
                snk=snk+a[d[0][1]+1]-a[d[0][1]]
    print(abs(snk-arg))

Submission status: Wrong Answer

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

if n==2:
    print(abs(a[1]-a[0]))
else:
    for i in range(n):
        if a[i]<0:
            a[i]=-a[i]
        else:
            break
    a.sort(reverse=True)
    snk=a[0]
    arg=a[1]
    for i in range(2,n):
        if snk>=arg:
            arg=arg+a[i]
        else:
            snk=snk+a[i]
    print(abs(snk-arg))

Submission status: Wrong Answer

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]
ans = float('Inf')
for i in range(1, N):
    print(ans)
    kouho = abs(s[i] - ((s[-1]) - s[i]))
    if ans > kouho:
        ans = kouho
    #ans = min(ans, kouho)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
s_right = [0] * (N + 1)
s_left = [0] * (N + 1)
for i in range(N):
    s_left[i + 1] = s_left[i] + a[i]
    s_right[i + 1] = s_right[i] + a[N - 1 - i]
ans = float('Inf')
for i in range(1, N):
    print(ans)
    if ans > abs(s_left[i] - s_right[N - i]):
        ans = abs(s_left[i] - s_right[N - i])
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())),reverse=True)
ans=10**9
 
for i in range(1,len(A)):
  x=sum(A[0:i])
#  y=sum(A)-x
#  tmp=abs(x*2-sum(A))
  ans=min(ans,abs(x*2-sum(A)))
  if abs(x*2-sum(A))>ans:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
A=list(map(lambda x:int(x)*(-1),input().split()))
ans=10**9
heapq.heapify(A)
tmp=0
for i in range(1,len(A)):
  tmp+=heapq.heappop(A)
  ans=min(ans,abs(sum(A)-tmp))
  if abs(sum(A)-tmp)>ans:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
A=list(map(lambda x:int(x)*(-1),input().split()))
ans=10**9
heapq.heapify(A)
tmp=0
for i in range(1,len(A)):
  tmp+=heapq.heappop(A)
  ans=min(ans,abs(sum(A)-tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
A=list(map(lambda x:int(x)*(-1),input().split()))
ans=10**9
heapq.heapify(A)
print(A)
tmp=0
for i in range(1,len(A)):
  tmp+=heapq.heappop(A)
  ans=min(ans,abs(sum(A)-tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
A=list(map(int,input().split()))
ans=10**9
heapq.heapify(A)
tmp=0
for i in range(1,len(A)):
  tmp+=heapq.heappop(A)
  ans=min(ans,abs(sum(A)-tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
A=sorted(list(map(int,input().split())))
ans=10**9
heapq.heapify(A)
tmp=0
for i in range(1,len(A)):
  tmp+=heapq.heappop(A)
  ans=min(ans,abs(sum(A)-tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=10**9

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a =[int(i)  for i in input().split()]
z = sum(a)
ans = 10**20
c = 0

for i in range(n-1):
    c += a[i]
    d = z - a[i]
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a =[int(i)  for i in input().split()]
z = sum(a)
ans = 10**20
c = a[0]
for i in range(1,n):
    c += a[i]
    d = z - c
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a =[int(i)  for i in input().split()]
b = sum(a) // 2
z = sum(a)
ans = 10**20
c = 0
for i in range(n):
    c += a[i]
    d = z - c
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a =[int(i)  for i in input().split()]
b = sum(a) // 2
c = 0
for i in range(n):
    c += a[i]
    if c > b:
        d = i
        break

e = abs(sum(a[:d+1]) - sum(a[d+1:]))
f = abs(sum(a[:d]) - sum(a[d:]))

if e > f:
    ans = f
else:
    ans = e
if n == 2:
    ans = e
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    cards = [int(item) for item in input().split()]

    all_sum = sum(cards)

    
    def candi_abs(sumu):
        # print(sumu, all_sum - sumu, abs(2*sumu - all_sum))
        return abs(2*sumu - all_sum)

    res = 10**9 +1
    sumu = 0
    for i in range(N-1):
        sumu += cards[i] 
        res = min(res, candi_abs(sumu))

    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

ans = 10 ** 20

s1 = a[0]
s2 = sum(a[1:])
ans = abs(s1 - s2)
if len(a)==2:
    print(ans)
else:
    for i in range(1, N):
        s1 = s1 + a[i]
        s2 = s2 - a[i]
        ans = min(ans, abs(s1 - s2))

    print(ans)

Submission status: Wrong Answer

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

accum=[0]
for i in range(N):
    accum.append(accum[i]+a[i])

accum.remove(0)
print(accum)
S=accum[-1]
lst=[]
for i in range(N-1):
    lst.append(abs(S-accum[i]*2))
print(min(lst))

Submission status: Wrong Answer

Solution code:
import numpy

N = int(input())
List = list(map(int,input().split()))
cumsum = numpy.cumsum(List)
total = sum(List)
result = [abs(total -item*2) for item in cumsum ]
print(min(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=[]
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);x=10**9;p=0
S.append(A[0])
for i in range(1,N):
  S.append(S[i-1]+A[i])
#print(S)
C[0]=abs(A[0]-(S[-1]-S[0]))
for i in range(1,N-1):
  C[i]=abs(C[i-1]+A[i]-(S[-1]-S[i]))
  if x>C[i]:
    x=C[i]
    p=i
print(abs(C[p-1]+A[p]-(S[-1]-S[p])))

Submission status: Wrong Answer

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]
C=[0]*(N)
C[0]=-s[N]
x=10**10
p=0
for i in range(1, N):
    C[i]=C[i-1]+2*A[i-1]
    if x>abs(C[i]):
        x=abs(C[i])
        p=i
print(x)
print(C)

Submission status: Wrong Answer

Solution code:
S=[]
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);x=10**9;p=0
S.append(A[0])
for i in range(1,N):
  S.append(S[i-1]+A[i])
#print(S)
C[0]=abs(A[0]-(S[-1]-S[0]))
for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-(S[-1]-S[i]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-(S[-1]-S[p])))

Submission status: Wrong Answer

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]
C=[0]*(N)
C[0]=-s[N]
x=10**9
p=0
for i in range(1, N):
    C[i]=C[i-1]+2*A[i-1]
    if x>abs(C[i]):
        x=abs(C[i])
        p=i
print(x)
#print(C)

Submission status: Wrong Answer

Solution code:
S=[]
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);C[0]=abs(A[0]-sum(A[1:]));x=10**9;p=0
S.append(A[0])
for i in range(1,N):
  S.append(S[i-1]+A[i])
#print(S)

for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-(S[-1]-S[i]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-(S[-1]-S[p])))

Submission status: Wrong Answer

Solution code:
S=[]
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);C[0]=abs(A[0]-sum(A[1:]));x=10**9;p=0
S.append(A[0])
for i in range(1,N):
  S.append(S[i-1]+A[i])
#print(S)

for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-(sum(A)-S[i]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-(sum(A)-S[p])))

Submission status: Wrong Answer

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]
C=[0]*(N);C[0]=abs(A[0]-(s[N]-s[0]));x=10**9;p=0
for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-(s[N]-s[i]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-(s[N]-s[p])))

Submission status: Wrong Answer

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]
C=[0]*(N);C[0]=abs(A[0]-(s[N]-s[1]));x=10**9;p=0
for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-(s[N]-s[i]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-(s[N]-s[p])))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

B=[0]*N
B[0] = A[0]
saitei = float("inf")
for i in range(1, N):
    B[i] += B[i-1]
    saitei = min(abs(B[i]-(a-B[i])), saitei)

print(saitei)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);C[0]=abs(A[0]-sum(A[1:]));x=10**9;p=0
for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-sum(A[i+1:]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-sum(A[p+1:])))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
M=N;SU=0;AR=0;C=[0]*(N);C[0]=abs(A[0]-sum(A[1:]));x=10**9;P=0
for i in range(1,N):
  if N-i==1:
    p=0
    break
  else:
    C[i]=abs(C[i-1]+A[i]-sum(A[i+1:]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-sum(A[p+1:])))

Submission status: Wrong Answer

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

total = sum(a)
ans = []
for x in range(0, n):
  total -= 2*a[x]
  ans.append(abs(total))

print(min(ans))

Submission status: Wrong Answer

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

total = sum(a)
ans = []
for x in range(0, n):
  ans.append(abs(total - 2*sum(a[:x+1])))

print(min(ans))

Submission status: Wrong Answer

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

    y = sum(A)
    x = 0
    mn = float('inf')
    for a in A:
        x += a
        y -= a
        if y != 0:
            mn = min(mn, abs(x-y))
    
    print(mn)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x=0
k=sum(a)
m = 3*(10**5)

for i in range(n-1):
  x+=a[i]
  if m>abs(2*x-k):
    m=abs(2*x-k)
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x=0
k=sum(a)
m = 3*10**6
"""
if sum(a)==0 and n>2:
  print(0)
  exit()
  """
for i in range(n-1):
  x+=a[i]
  if m>abs(2*x-k):
    m=abs(2*x-k)
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x=0
k=sum(a)
m = 3*10**5
if sum(a)==0 and n>2:
  print(0)
  exit()
for i in range(n-1):
  x+=a[i]
  if m>abs(2*x-k):
    m=abs(2*x-k)
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x=0
y=0
a.sort()
min=10**6
if sum(a)==0 and n>2:
  print(0)
  exit()
for i in range(n-1):
  x+=a[i]
  if min>abs(2*x-sum(a)):
    min=abs(2*x-sum(a))
print(min)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

x = 0
for a in A:
    x += a
    y = S - x
    ans = min(ans, abs(x-y))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# Problem C - Splitting Pile

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

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

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

# output
print(min_cost)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

n = ni()
a = na()

import numpy as np
a = np.array(a)
a += 10**9
a = list(np.cumsum(a))

import bisect

ma = bisect.bisect_right(a,a[-1]/2)+1
mi = bisect.bisect_left(a,a[-1]/2)-1

ans = 100000000000000000

for i in range(mi,ma+1):
    if i < 0 or i > n-2:
        continue
    ans = min(ans, abs(a[-1]-a[i]*2))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

n = ni()
a = na()

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

import bisect

ma = bisect.bisect_right(a,a[-1]/2)+1
mi = bisect.bisect_left(a,a[-1]/2)-1

ans = 100000000000000000

for i in range(mi,ma+1):
    if i < 0 or i > n-2:
        continue
    ans = min(ans, abs(a[-1]-a[i]*2))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

n = ni()
a = na()

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

import bisect

ma = bisect.bisect_right(a,a[-1]/2)
mi = bisect.bisect_left(a,a[-1]/2)-1

ans = 100000000000000000

for i in range(mi,ma+1):
    if i < 0 or i > n-2:
        continue
    ans = min(ans, abs(a[-1]-a[i]*2))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

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

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

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

n = ni()
a = na()

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

import bisect

ma = bisect.bisect_right(a,a[-1]/2)
mi = bisect.bisect_left(a,a[-1]/2)-1

ma = ma if ma < n-1 else n-2
mi = mi if mi > 0 and mi < n-1 else 0
mid = mi+1 if mi < n-1 else mi

print(min(abs(a[-1]-a[ma]*2), abs(a[-1]-a[mi]*2), abs(a[-1]-a[mid]*2)))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

n = ni()
a = na()

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

import bisect

ma = bisect.bisect_right(a,a[-1]/2)+1
mi = bisect.bisect_left(a,a[-1]/2)-1

ma = ma if ma < n-1 else n-2
mi = mi if mi > 0 and mi < n-1 else 0
mid = mi+1 if mi < n-1 else mi

print(min(abs(a[-1]-a[ma]*2), abs(a[-1]-a[mi]*2), abs(a[-1]-a[mid]*2)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ruiseki = [0]*(N+1)
total = 0
now = 10**9+7
sa = 0
now_2 = 0
for i in range(N):
  total += A[i]
  ruiseki[i+1] = total
for i in range(1,len(ruiseki)-1):
  snuke = ruiseki[i]-ruiseki[0]
  arai = ruiseki[N]-ruiseki[i]
  now_2 = abs(snuke-arai)
  now = min(now,now_2)
print(now)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
p = sum(a)//2
snuke = 0
arai = 0
for i in range(N):
  if i == N-1:
    arai = a[-1]
    break
  snuke += a[i]
  if snuke >= p:
    arai = sum(a)-snuke
    break
print(abs(snuke-arai))