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

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

Submission status: Wrong Answer

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

res = 1e+9
n = sum(a)
for i in range(1,N):
    x = sum(a[:i])
    y = n - x
    #y = sum(a[i:])
    tmp = abs(x-y)
    res = min(tmp,res)
print(res)

Submission status: Wrong Answer

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

res = 1e+9
for i in range(1,N):
    x = sum(a[:i])
    y = sum(a[i:])
    tmp = abs(x-y)
    res = min(tmp,res)
print(res)

Submission status: Wrong Answer

Solution code:
# ABC067 C Splitting Pile

import itertools
import bisect

n = int(input())
a_list = [int(x) for x in input().split()]
c_list = list(itertools.accumulate(a_list))

_sum = c_list[-1]
_ans= float("Inf")
for i in range(1,len(c_list)-1,1):
    _ans = min(_ans,abs(_sum - 2*c_list[i]))
print(abs(_ans))

Submission status: Wrong Answer

Solution code:
# ABC067 C Splitting Pile

import itertools
import bisect

n = int(input())
a_list = [int(x) for x in input().split()]
c_list = list(itertools.accumulate(a_list))

_sum = c_list[-1]
_ans= float("Inf")
# _idx = bisect.bisect_left(c_list, _sum//2)
_idx = 0
for i in range(len(c_list)):
    _ans = min(_ans,abs(_sum - 2*c_list[i]))
print(abs(_ans))

Submission status: Wrong Answer

Solution code:
# ABC067 C Splitting Pile

import itertools
import bisect

n = int(input())
a_list = [int(x) for x in input().split()]
c_list = list(itertools.accumulate(a_list))

_sum = c_list[-1]
_ans= float("Inf")
# _idx = bisect.bisect_left(c_list, _sum//2)
_idx = 0
for i in range(len(c_list)):
    _tmp = abs(_sum - 2*c_list[i])
    if _ans > _tmp:
        _ans = _tmp
print(abs(_ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

whole = a.sum()
div = np.abs(a.cumsum() - whole / 2).argmin()

if div == 0 or div == (n - 1):
    print(min(np.abs(a[0] - a[1:].sum()), np.abs(a[:-1].sum() - a[-1])))
else:
    print(np.abs(a[:div + 1].sum() - a[div + 1:].sum()))

Submission status: Wrong Answer

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

whole = sum(a)

if n == 2:
    print(abs(a[0] - a[1]))
else:
    now = 0
    ans = float("inf")
    for i in a:
        now += i
        diff = abs(whole - 2 * now)
        ans = min(ans, diff)

    print(ans)

Submission status: Wrong Answer

Solution code:
#4問目
N = int(input())
a = list(map(int, input().split()))
#足していった配列を用意する
Sum = 0
Min = float("inf")
SumArray = [0] * N
for i in range(N):
    Sum += a[i]
    SumArray[i] = Sum
#仕切りを用意して，左側をすぬけくん，右側をアライグマのカードとして差分を計算する
if N == 2:
    print(abs(a[0] - a[1]))
else:
    for i in range(N):
        temp = abs(SumArray[i] - (SumArray[N-1] - SumArray[i]))
        if temp < Min:
            Min = temp

    print(int(Min))

Submission status: Wrong Answer

Solution code:
#4問目
N = int(input())
a = list(map(int, input().split()))
#足していった配列を用意する
Sum = 0
Min = 2 * 10**5
SumArray = [0] * N
for i in range(N):
    Sum += a[i]
    SumArray[i] = Sum
#仕切りを用意して，左側をすぬけくん，右側をアライグマのカードとして差分を計算する
if N == 2:
    print(abs(a[0] - a[1]))
else:
    for i in range(N):
        temp = abs(SumArray[i] - (SumArray[N-1] - SumArray[i]))
        if temp < Min:
            Min = temp

    print(Min)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
goukei=sum(A)
for i in range(1,n):
    A[i]+=A[i-1]
ans=100000000000
for j in range(n):
    ans=min(ans,abs(A[j]-(goukei-A[j])))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
goukei=sum(A)
for i in range(1,n):
    A[i]+=A[i-1]
ans=100000
for j in range(n):
    ans=min(ans,abs(A[j]-(goukei-A[j])))
print(ans)

Submission status: Wrong Answer

Solution code:
#4問目
N = int(input())
a = list(map(int, input().split()))
#足していった配列を用意する
Sum = 0
Min = 2 * 10**5
SumArray = [0] * N
for i in range(N):
    Sum += a[i]
    SumArray[i] = Sum
#仕切りを用意して，左側をすぬけくん，右側をアライグマのカードとして差分を計算する
for i in range(N-1):
    temp = abs(SumArray[i] - (SumArray[N-1] - SumArray[i]))
    if temp < Min:
        Min = temp
        
print(Min)

Submission status: Wrong Answer

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

sum_a = sum(A)
cum_a = [0]*n
cum_a[0] = A[0]

ans = abs(sum_a-cum_a[0])

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

Submission status: Wrong Answer

Solution code:
import collections


def main():
    n = int(input())
    a = input_list()
    sum_a = sum(a)
    wa = []
    for i, v in enumerate(a):
        if i == 0:
            wa.append(v)
        else:
            wa.append(v+wa[i-1])
    ans = 10**7
    for i in range(n-1):
        ans = min(ans, abs(sum_a-(wa[i]*2)))
    print(ans)


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,A:list) -> int:
   accum = [A[0]]
   ans = 10 * 10
   total = sum(A)
   for i in range(1,N):
      accum.append(accum[i-1] + abs(A[i]))
   # print(accum)
   for a in accum:
      ans = min(ans,abs(a - (total - a)))
      # print(ans)

   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:

def myAnswer(N:int,A:list) -> int:
   accum = [A[0]]
   total = sum(A)
   ans = 10 * 10
   for i in range(1,N):
      accum.append(accum[i-1] + A[i])
   accum.pop()
   for a in accum:
      ans = min(ans,abs(a - (total - a)))
      # print(ans)

   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

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

l = [0]*n
l[0] = a[0] - sum(a[1:])

for i in range(1,n):
    if a[i] >= 0:
        l[i] = l[i-1] + (2 * a[i])
    else:
        l[i] = l[i-1] - (2 * a[i])

abs_l = [abs(x) for x in l]
print(min(abs_l))

Submission status: Wrong Answer

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

all_sum = sum(li)
x = 0
y = all_sum
ans = 10**18

for i in range(n):
    x += li[i]
    y -= li[i]

    if ans >= abs(x-y):
        ans = abs(x-y)
    else:
        break

    if i == n - 2:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = pow(10, 15)
key = sum(a)
p = 0
for i in range(n):
  p += a[i]
  if ans > abs(key-2*p):
    ans = abs(key-2*p)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = pow(10, 15)
key = sum(a)
p = key
for i in range(n):
  p += a[i]
  if ans > abs(key-2*p):
    ans = abs(key-2*p)
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque
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):
    x += a[i]
    y -= a[i]
    ans = min(abs(x-y),ans)

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

x = sum(a)
ans = 0
for i in range(n):
  ans += a[i]
  if ans >= x / 2:
    print(2 * ans - x)
    quit()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
target = sum(a) / 2
s = []
for i in range(len(a)):
    s.append(a[i])
    if sum(s) >= target:
        break

x = a[:i]
y = a[i:]
print(abs(sum(x)-sum(y)))

Submission status: Wrong Answer

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(ans, abs(x - y))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
d = sum(a)
snuke = 0
arai = 0
ans = 1000000000
for i in range(n-1):
    snuke += a[i]
    arai = d - snuke
    ans = min(ans,abs(snuke-arai))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
a.sort()
a2 = []
c = 0
d = sum(a)
snuke = 0
arai = 0
ans = 1000000000
for i in range(n-1):
    snuke += a[i]
    arai = d - snuke
    ans = min(ans,abs(snuke-arai))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum_a=0
slist=[]
for a in alist:
  sum_a+=a
  slist.append(sum_a)
#print(slist)

allsum=slist[-1]
answer=10**9
for i in range(N-1):
  cand=abs(allsum-2*slist[i])
  answer=min(answer,cand)
  #print(slist[i],allsum-slist[i],abs(allsum-2*slist[i]))
  
print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
total=sum(a)
cnt=0
i=0
while(cnt<=total/2):
  cnt+=a[i]
  i+=1
if i!=1:
  print(min(abs((total-cnt)-cnt),abs((total-cnt+a[i-1])-(cnt-a[i-1]))))
else:
  print(abs((total-cnt)-cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_A = sum(A)
ans = 10**20
X = 0
for a in A:
    X += a
    ans = min(ans,abs(sum_A-2*X))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sunuke = 0
arai = 0
sunuke_pos = 0
arai_pos = N-1
for i in range(N):
    if sunuke <= arai:
        sunuke += A[sunuke_pos]
        sunuke_pos += 1      
    else:
        arai += A[arai_pos]
        arai_pos -=1
    

print(abs(sunuke-arai))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = int(1e9)
for i in range(N-1):
    ans = min(ans, abs(sa[i] - (sa[-1] - sa[i])))
print(ans)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# 累積和
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cum_sum = [0]*n

total = 0
for i in range(n):
    total += a[i]
    cum_sum[i] = total

max_sum = cum_sum[-1]
dp = [0] * n
dp[0] = 10**9
for i in range(n-1):
    dp[i+1] = min(dp[i], abs(cum_sum[i]-(max_sum-cum_sum[i])))

print(min(dp))

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
cum_sum = [0]*n

total = 0
for i in range(n):
    total += a[i]
    cum_sum[i] = total

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=1000000000
for i in range(N-1):
    S=S-a[i]
    SS=SS+a[i]
    if mi>=abs(S-SS):
        mi=abs(S-SS)
print(mi)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=abs(S-SS)
for i in range(N):
  S=S-a[i]
  SS=SS+a[i]
  if mi>=abs(S-SS):
    mi=abs(S-SS)
print(mi)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=abs(S-SS)
for i in range(N):
  S=S-a[i]
  SS=SS+a[i]
  print(S,SS)
  if mi>=abs(S-SS):
    mi=abs(S-SS)
print(mi)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
print(a)
S=sum(a[1:])
SS=a[0]
mi=abs(S-SS)
for i in range(1,N-1):
    if mi>=abs(S-SS-2*a[i]):
      
      S=S-a[i]
      SS=SS+a[i]
      mi=abs(S-SS)
    else:
      S=S-a[i]
      SS=SS+a[i]
        
print(mi)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a[1:])
SS=a[0]
mi=abs(S-SS)
for i in range(1,N-1):
    if mi>=abs(S-SS-2*a[i]):
        S=S-a[i]
        SS=SS+a[i]
        mi=abs(S-SS)
print(mi)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a)
SS=0
mi=abs(S-SS)
for i in range(N):
    if mi>=abs(S-SS-2*a[i]):
        S=S-a[i]
        SS=SS+a[i]
        mi=abs(S-SS)
print(mi)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a[1:])
SS=a[0]
mi=abs(S-SS)
for i in range(1,N-1):
    if mi>=abs(S-SS-2*a[i]):
        S=S-a[i]
        SS=SS+a[i]
        mi=abs(S-SS)
print(mi)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=sum(a[1:])
SS=a[0]
mi=abs(S-SS)
for i in range(1,N-1):
    if mi>abs((S-a[i])-(SS+a[i])):
        S-=a[i]
        SS+=a[i]
        mi=abs(mi-2*a[i])
print(mi)

Submission status: Wrong Answer

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

s = [0]*(n-1)
s[0] = a[0]
A = sum(a)
ans = 1e100
for i in range(n-2):
  s[i+1] = s[i] + a[i+1]

for t in s:
  ans = min(ans, abs(2*t - A))

Submission status: Wrong Answer

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

t = sum (a)
ans = 10 ** 9 + 1
X = 0
for i, x in enumerate(a):
    X += x
    Y = t - X
    ans = min(ans, abs(X-Y))
    if i+ 1 == n -1:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
Min = np.inf
s = 0
for i in range(len(a)-1):
    s += a[i]
    Min = min(Min, abs(2 * s- total))

Submission status: Wrong Answer

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

total = sum(A)

ans = float("inf")
for i in range(1, N-1):
    cand = abs(2*sum(A[:i]) - total)
    ans = min(ans, cand)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort();
sum = int(0)
arai = int(0)
ans = int(0)
mini = float('inf')

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

print(int(mini))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort();
sum = int(0)
arai = int(0)
ans = int(0)
mini = int(1000000001)
for i in range(N):
	sum+=a[i]
for i in range(N-1):
	ans+=a[i]
	arai=sum-ans
	mini=min(mini,abs(ans-arai))

print(mini)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort();
ans = int(0)
arai = int(0)
now = int(0)
mini = int(1000000001)
for i in range(N):
	ans+=a[i]
for i in range(N-1):
	now+=a[i]
	arai=ans-now
	mini=min(mini,abs(now-arai))

print(mini)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
S = sum(a)
counter = 0
ans = 1000000100
for i in range(n-1):
    counter+=a[i]
    rest = S-counter
    diff = abs(counter-rest)
    ans = min(ans,diff)
print(ans)

Submission status: Wrong Answer

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

if n >=5:
    print(sum(num[4:])-sum(num[:4]))
else:
    print(sum(num[::2])-sum(num[1::2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int,input().split()))
sum_cnt = sum(num_list)
sunuke = 0
arai = 0
tmp = 0
tmp_list = []
for i in range(len(num_list)):
    if i == 0:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
        tmp_list.append(tmp)
    else:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
        tmp_list.append(tmp)
print(min(tmp_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int,input().split()))
sum_cnt = sum(num_list)
sunuke = 0
arai = 0
tmp = 0
for i in range(len(num_list)):
    if i == 0:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
    else:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        if tmp - abs(arai - sunuke) <= 0:
            break
        else:
            tmp = abs(arai - sunuke)
print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int,input().split()))
sum_cnt = sum(num_list)
sunuke = 0
arai = 0
tmp = 0
for i in range(len(num_list)-1):
    if i == 0:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
    else:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        if tmp - abs(arai - sunuke) <= 0:
            break
        else:
            tmp = abs(arai - sunuke)
print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int,input().split()))
sum_cnt = sum(num_list)
sunuke = 0
arai = 0
tmp = 0
for i in range(len(num_list)):
    if i == 0:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        tmp = abs(arai - sunuke)
    else:
        sunuke += num_list[i]
        arai = (sum_cnt - sunuke)
        if tmp - abs(arai - sunuke) <= 0:
            print(tmp)
            break
        else:
            tmp = abs(arai - sunuke)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
S = a[0]
A = a[1]
for i in a[2:]:
    if abs(S + i - A) <= abs(S - A - i):
        S += i
    else:
        A += i
print(abs(S - A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
S = a[0]
A = a[n - 1]
for i in a[1:n - 1]:
    if abs(S + i - A) <= abs(S - A - i):
        S += i
    else:
        A += i
print(abs(S - A))

Submission status: Wrong Answer

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

print(mini)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
x = 0
y = 0
a = 0
b = 0
list_A.sort(key=lambda x:abs(x), reverse=True)
for num in list_A:
    if num > 0:
        if x > y:
            y += num
            b += 1
        else:
            x += num
            a += 1
    else:
        if x < y:
            y += num
            b += 1
        elif num == 0:
            a += 1
            b += 1
        else:
            x += num
            a += 1

if a == 0 or b == 0:
    list_A.sort(key=lambda x:abs(x))
    x = list_A.pop(0)
    y = list_A.pop(0)
    list_A.sort(key=lambda x: abs(x), reverse=True)
    for num in list_A:
        if num > 0:
            if x > y:
                y += num
            else:
                x += num
        else:
            if x < y:
                y += num
            else:
                x += num

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
x = 0
y = 0
a = 0
b = 0
list_A.sort(key=lambda x:abs(x), reverse=True)
for num in list_A:
    if num > 0:
        if x > y:
            y += num
            b += 1
        else:
            x += num
            a += 1
    else:
        if x < y:
            y += num
            b += 1
        else:
            x += num
            a += 1

if a == 0 or b == 0:
    list_A.sort(key=lambda x:abs(x))
    x = list_A.pop(0)
    y = 0
    list_A.sort(key=lambda x: abs(x), reverse=True)
    for num in list_A:
        if num > 0:
            if x > y:
                y += num
            else:
                x += num
        else:
            if x < y:
                y += num
            else:
                x += num

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
x = 0
y = 0
a = 0
b = 0
list_A.sort(key=lambda x:abs(x), reverse=True)
for num in list_A:
    if num > 0:
        if x > y:
            y += num
            b += 1
        else:
            x += num
            a += 1
    else:
        if x < y:
            y += num
            b += 1
        else:
            x += num
            a += 1

if a == 0 or b == 0:
    list_A.sort(key=lambda x:abs(x))
    x = list_A.pop(0)
    y = list_A.pop(0)
    list_A.sort(key=lambda x: abs(x), reverse=True)
    for num in list_A:
        if num > 0:
            if x > y:
                y += num
            else:
                x += num
        else:
            if x < y:
                y += num
            else:
                x += num

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
x = 0
y = 0
a = 0
b = 0
list_A.sort(key=lambda x:abs(x), reverse=True)
for num in list_A:
    if num > 0:
        if x > y:
            y += num
            b += 1
        else:
            x += num
            a += 1
    else:
        if x < y:
            y += num
            b += 1
        else:
            x += num
            a += 1

if a == 0 or b == 0:
    list_A.sort(key=lambda x:abs(x))
    x = list_A.pop(0)
    y = list_A.pop(0)
    for num in list_A:
        if num > 0:
            if x > y:
                y += num
                b += 1
            else:
                x += num
                a += 1
        else:
            if x < y:
                y += num
                b += 1
            else:
                x += num
                a += 1
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort(key=lambda x:abs(x))
x = list_A.pop(0)
y = list_A.pop(0)
list_A.sort(key=lambda x:abs(x), reverse=True)
for num in list_A:
    if num > 0:
        if x > y:
            y += num
        else:
            x += num
    else:
        if x < y:
            y += num
        else:
            x += num

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort(key=lambda x:abs(x))
x = list_A.pop(0)
y = list_A.pop(0)
list_P = []
list_M = []
for num in list_A:
    if num > 0:
        list_P.append(num)
    else:
        list_M.append(num)

list_P.sort(reverse=True)
list_M.sort()

for num in list_P:
    if x > y:
        y += num
    else:
        x += num

for num in list_M:
    if x < y:
        y += num
    else:
        x += num

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
x = list_A.pop(0)
y = list_A.pop(0)
list_A.sort(key=lambda x:abs(x))
list_P = []
list_M = []

for num in list_A:
    if num > 0:
        list_P.append(num)
    else:
        list_M.append(num)

list_P.sort(reverse=True)
list_M.sort()

for num in list_P:
    if x > y:
        y += num
    else:
        x += num

for num in list_M:
    if x < y:
        y += num
    else:
        x += num

print(abs(x-y))

Submission status: Wrong Answer

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

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_A.sort(reverse=True)
x = list_A[0]
y = list_A[1]
for i in range(2, n):
    if  x < y:
        x += list_A[i]
    else:
        y += list_A[i]

print(abs(x-y))