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 = [int(i) for i in input().split()]
A_sum = sum(A)
deltas = [A_sum]
for i in range(N-1):
    deltas.append(abs(deltas[-1] - 2*A[i]))
print(min(deltas[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC067C
N=int(input())
a=list(map(int,input().split()))
x=a[0]
y=sum(a)-x
for i in range(N-1):
    if i!=0:
        if abs(x-y)>abs(x-y+2*a[i]):
            x+=a[i]
            y-=a[i]
        else:
            break
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
#ABC067C
N=int(input())
a=list(map(int,input().split()))
x=a[0]
y=sum(a)-x
for i in range(N-1):
    if i!=0:
        if abs(x-y)>abs(x-y+2*a[i]):
            x+=a[i]
            y-=a[i]
        else:
            print(abs(x-y))
            exit()
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
#ABC067C
N=int(input())
a=list(map(int,input().split()))
x=a[0]
y=sum(a)-x
for i in range(N-1):
    if i!=0:
        if abs(x-y)>abs(x-y+2*a[i]):
            x+=a[i]
            y-=a[i]
        else:
            print(min(abs(x-y),abs(x-y-2*a[i])))
            exit()
print(abs(x-y))

Submission status: Wrong Answer

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

sunuke   = a[0]
araiguma = sum(a[1:])
result = abs(sunuke-araiguma)
for i in range(1,N):
  sunuke += a[i]
  araiguma -= a[i]
  result = min(result, abs(sunuke-araiguma))

print(result)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

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

Submission status: Wrong Answer

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

cum_sum = [sum(A[:i+1]) for i in range(len(A))]
b = cum_sum[-1]

print(cum_sum)
ans = float("inf")

for a in cum_sum[:-1]:
    ans = min(ans, abs(2 * a - b))

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
b=[]
sum=0
for a in A:
    sum+=a
    b.append(sum)

print(b)
ans=float("inf")
for i in range(0,N-1):
    if ans>abs(b[-1]-b[i]*2):
        ans=abs(b[-1]-b[i]*2)
print(ans)

Submission status: Wrong Answer

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

S = sum(A)
count = 0
Near = 10 ** 15
for i in range(N-1):
    count = count + A[i]
    if abs(2 * Near - S) > abs(2 * count - S):
        Near = count
print(abs(2 * count - S))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as acc
input()
cards=sorted(map(int,input().split()))
sum=sum(cards)
print(min(abs(sum-x*2)for x in tuple(acc(cards))[:-1]))

Submission status: Wrong Answer

Solution code:
a = int(input())

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

for i in range(1,a):
  aa[i] += aa[i-1]
  
su = 10**20

for i in range(a):
  su = min(su,abs(aa[a-1]-2*aa[i]))
print(su)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

if N > 2:
    B = [x for x in accumulate(A)]
    ans = float('inf')
    for i in range(N):
        x = B[i]
        y = B[-1] - B[i]
        ans = min(ans, abs(x - y))
else:
    ans = abs(A[0] - A[-1])
print(ans)

Submission status: Wrong Answer

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

total = sum(A)
avg = total / 2

ans = 10**9
nusuke = 0
for a in A[:-1]:
    nusuke += a
    ans = min(ans, abs(nusuke - (total - nusuke)))

print(ans)

Submission status: Wrong Answer

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

total = sum(A)
avg = total / 2

nusuke = A[0]
last = 0
for a in A[1:-1]:
    last = a
    if nusuke + a > avg: break
    nusuke += a

print(min(abs(nusuke + last - (total - (nusuke + last))),
          abs(nusuke - (total - nusuke))))

Submission status: Wrong Answer

Solution code:
import functools

N = int(input())
A = [int(x) for x in input().split()]
A = sorted(A, key=functools.cmp_to_key(lambda x, y: abs(x) - abs(y)), reverse=True)

b, c = A[:2]
for a in A[2:]:
    if abs((b + a) - c) < abs(b - (c + a)):
        b += a
    else:
        c += a
print(abs(b - c))

Submission status: Wrong Answer

Solution code:
import functools

N = int(input())
A = [int(x) for x in input().split()]
A = sorted(A, key=functools.cmp_to_key(lambda x, y: abs(x) - abs(y)), reverse=True)

b, c = A[-2:]
for a in A[:-2]:
    if abs((b + a) - c) < abs(b - (c + a)):
        b += a
    else:
        c += a
print(abs(b - c))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

B = [x for x in accumulate(A[1:-1])]
ans = abs(A[0] - A[-1])
for i in range(N - 2):
    x = A[0] + B[i]
    y = A[-1] + (B[-1] - B[i])
    ans = min(ans, abs(x - y))
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

B = [x for x in accumulate(A)]
index = 0
x = float('inf')
m = B[-1] // 2
for i in range(N):
    if x > abs(B[i] - m):
        x = abs(B[i] - m)
        index = i

if index == 0:
    index = 1
elif index == N - 1:
    index = N - 2

ans1 = abs(B[index] - (B[-1] - B[index]))

index = 0
x = float('inf')
m = B[-1] // 2 + 1
for i in range(N):
    if x > abs(B[i] - m):
        x = abs(B[i] - m)
        index = i

if index == 0:
    index = 1
elif index == N - 1:
    index = N - 2

ans2 = abs(B[index] - (B[-1] - B[index]))
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

B = [x for x in accumulate(A)]
index = 0
x = float('inf')
m = B[-1] / 2
for i in range(N):
    if x > abs(B[i] - m):
        x = abs(B[i] - m)
        index = i

if index == 0:
    index = 1
elif index == N - 1:
    index = N - 2

ans = abs(B[index] - (B[-1] - B[index]))
print(ans)

Submission status: Wrong Answer

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

min_num = 1000000000000
for i in range(1, n):
	abs_num = abs(sum(a[:i]) - sum(a[:i]))
	if abs_num < min_num:
		min_num = abs_num

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
n=int(input())
l=list(ac(map(int,input().split())))
a=l[-1]
print(min(abs(a-2*i) for i in l))

Submission status: Wrong Answer

Solution code:
def inpl(): return input().split()

n = int(input())
a = list(map(int, inpl()))
a = sorted(a, reverse=True)

ans = 0
for i in range(n):
    ans = abs(ans - a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = sum(a)
a_sum = 0
for i in range(n-1):
    x = abs(-a_sum+2*sum(a[:i+1]))
    if ans == 0 or x < ans:
        ans = x
print(ans)

Submission status: Wrong Answer

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

tot = sum(A)

res = 0
s, t = A[0], sum(A[1:])
min_dif = abs(s - t)
for a in A[1:-1]:
    s += a
    t -= a
    dif = abs(s - t)
    if min_dif > dif:
        min_dif = dif
    else:
        print(min_dif)
        exit()

print(abs(s - A[-1]))

Submission status: Wrong Answer

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

tot = sum(A)

res = 0
s, t = A[0], sum(A[1:])
min_dif = abs(s - t)
for a in A[1:-1]:
    s += a
    t -= a
    dif = abs(s - t)
    if min_dif > dif:
        min_dif = dif
    else:
        print(dif)
        exit()

print(abs(s - A[-1]))

Submission status: Wrong Answer

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

min_abs = 10000000000
for n_i in range(1,n):
    if abs(sum(a[:n_i]) - sum(a[n_i:])) < min_abs:
        min_abs = abs(sum(a[:n_i]) - sum(a[n_i:]))
    else:
        break
print(min_abs)

Submission status: Wrong Answer

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

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + i
        index += 1

    mapped_list = map(lambda x: ruiseki_list[N]-x, ruiseki_list)
    result_list = [abs(a-b) for (a, b) in zip(mapped_list, ruiseki_list)]
    print(result_list)
    print(min(result_list[2:N]))

Submission status: Wrong Answer

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

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + i
        index += 1

    for i in range(2, N):
        cal = abs(ruiseki_list[N] - 2 * ruiseki_list[i])
        print(cal)
        if cal < result:
            result = cal
    print(result)

Submission status: Wrong Answer

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

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + i
        index += 1

    for i in range(2, N-1):
        cal = abs(ruiseki_list[N] - 2 * ruiseki_list[i])
        if cal < result:
            result = cal
    print(result)

Submission status: Wrong Answer

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

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + int(i)
        index += 1

    for i in range(2, N-1):
        cal = abs(ruiseki_list[N] - 2 * ruiseki_list[i])
        if cal < result:
            result = cal
    print(result)

Submission status: Wrong Answer

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

jx,jy=0,0
for t in a:
    if t<=0:
        if x>=y:
            x+=t
            jx+=1
        else:
            y+=t
            jy+=1
    elif x>=y:
        y+=t
        jy+=1
    else:
        x+=t
        jx+=1

if jx==0:
    y-=a[-1]
    x+=a[-1]
elif jy==0:
    x-=a[-1]
    y+=a[-1]

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
list01 = [int(x) for x in arr_data[1]]

sumdata = sum(list01)

middledata = sumdata // 2
#初期値
x = list01[0]
y = sumdata-x

for i in range(1, n-1):

#    print(x, list01[i], y, sumdata,x + list01[i], middledata, x + list01[i] > middledata)
    
    if abs(x + list01[i]) > abs(middledata):
         
        break
        
    else:
        
        x += list01[i]
        y = sumdata-x

#print(x, y, abs(x-y)) 
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
list01 = [int(x) for x in arr_data[1]]

sumdata = sum(list01)

#初期値
mytotal = abs(list01[0])

for i in range(1, n):
    
    if mytotal + abs(list01[i]) > abs(sumdata) // 2:
        
        break
        
    else:
        
        mytotal += abs(list01[i])
        
#print(sumdata, mytotal, sum(list01[i:]),abs(mytotal-sum(list01[i:])))
print(abs(mytotal-sum(list01[i:])))

Submission status: Wrong Answer

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

top = 0
under = sum(A)
result = 10**9
for a in A[:-1]:
    top += a
    under -= a
    if result > abs(top - under):
        result = abs(top-under)
print(result)

Submission status: Wrong Answer

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

top = 0
under = sum(A)
result = 10**9
for a in A[:-1]:
    top += a
    under -= a
    if result < abs(top - under):
        break
    result = abs(top-under)
print(result)

Submission status: Wrong Answer

Solution code:
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

list01 = list(map(int, arr_data[1]))

sumdata = 0

for v in list01:
    
    sumdata += abs(v)

mytotal = list01[0]

for i in range(1,n):
    
    if mytotal + list01[i] > sumdata // 2:
        
        break
        
    else:
        
        mytotal +=  list01[i]
        
print(abs(sumdata-mytotal-mytotal))

Submission status: Wrong Answer

Solution code:
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

list01 = list(map(int, arr_data[1]))

sumdata = 0

for v in list01:
    
    sumdata += abs(v)

mytotal = 0

for v in list01:
    
    if mytotal + v > sumdata // 2:
        
        break
        
    else:
        
        mytotal += v
        
print(sumdata-mytotal-mytotal)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

rui = [0] * N

rui[0] = A[0]
for it in range(1, N):
    rui[it] = rui[it - 1] + A[it]

ans = 1145141919810
for i in range(1, N):
    ans = min(abs(rui[i] - rui[N - 1] + rui[i]),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

rui = [0] * N

rui[0] = A[0]
for it in range(1, N):
    rui[it] = rui[it - 1] + A[it]

ans = 1145141919810
for i in range(1, N):
    ans = min(abs(rui[i] - rui[N - 1] - rui[i]),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

rui = [0] * N

rui[0] = A[0]
for it in range(1, N):
    rui[it] = rui[it - 1] + A[it]

ans = 1145141919810
for i in range(1, N):
    ans = min(rui[i], rui[N - 1] - rui[i])
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy
N = int(input())
cards = numpy.cumsum(list(map(int, input().split(' '))))
tmp = float('inf')
for i in range(N):
    diff = abs(cards[i] * 2 - cards[-1])
    tmp = min(tmp, diff)

print(tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = sorted(map(int, raw_input().split()), key=abs, reverse=True)

snuke = 0
arai = 0
sflag = True
aflag = True

for i in range(0, N):
	if i == N-1 and sflag: snuke = snuke + a[i]
	elif i == N-1 and aflag: arai = arai + a[i]
	else:
		difs = abs(snuke+a[i]-arai)
		difa = abs(snuke-arai-a[i])
		if difs < difa: snuke = snuke + a[i]
		else: arai = arai + a[i]

print abs(snuke-arai)

Submission status: Wrong Answer

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

a.sort()
s1 = sum(a)
s2, idx = a[0], 1
while s2 + a[idx] <= s1 / 2 and idx < len(a) - 1:
    s2 += a[idx]
    idx += 1

print(abs(s1-2*s2))

Submission status: Wrong Answer

Solution code:

n = int(input())
a = list(map(int,input().split()))
sss = 0
for i in range(n):
    sss=sss + a[i]
ppp = 0
qqq = abs(sss - 2 * a[0])
for i in range(n):
    ppp=ppp + a[i]
    qo = abs(sss-2*ppp)
    if qqq > qo:
        qqq=qo
        
print(qqq)

Submission status: Wrong Answer

Solution code:

n = int(input())
a = list(map(int,input().split()))
sss = 0
for i in range(n):
    sss=sss + a[i]
ppp = 0
qqq = abs(sss - a[0])
for i in range(n):
    ppp=ppp + a[i]
    qo = abs(sss-ppp)
    if qqq > qo:
        qqq=qo
        
print(qqq)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 10000000000
f, s = 0, sum(a)
for a_i in a:
    f += a_i
    s -= a_i
    ans = min(ans, abs(f-s))
if N == 2:
    ans = abs(a[0]-a[1])
print(ans)

Submission status: Wrong Answer

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

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

if n>3: 
 for i in range(1,n):
  ans=min(abs(s-2*a[i]),ans)
#  print(ans)
  s=s-2*a[i]
  
print(ans)

Submission status: Wrong Answer

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

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

if n>3: 
 for i in range(1,n):
  ans=min(abs(s-2*a[i]),ans)
  print(ans)
  s=s-2*a[i]
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

for i in range(1,n):

  ans=min(abs(ans-2*a[i]),ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,x,ans=int(input()),0,10**18
s=list(map(int,input().split()))
for j in s:
    x+=j
x=x-s[0]*2
for k in range(1,N-1):
    x=abs(x-s[k]*2)
    ans=min(ans,x)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def solve():
    ans = float("inf")
    araiguma = sum(A)
    snuke = 0
    for A_i in A:
        snuke += A_i
        araiguma -= A_i
        score = araiguma - snuke
        if score < ans:
            ans = score
    print(ans)


solve()

Submission status: Wrong Answer

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

def solve():
    ans = float("inf")
    araiguma = sum(A)
    snuke = 0
    for A_i in A:
        snuke += A_i
        araiguma -= A_i
        score = abs(araiguma - snuke)
        if score < ans:
            ans = score
    print(ans)


solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))
m = 1000000000;
for i in range(n):
    d = sum(s[:i]) - sum(s[i:])
    if n==2:
        m = min(m, abs(d))
    else:
        m = min(m, abs(d))
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))
m = 1000000000;
for i in range(n):
    d = sum(s[:i]) - sum(s[i:])
    if n==2:
        m = abs(d)
    else:
        m = min(m, abs(d))
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))
m = 1000000000;
if len(s)==2:
    print(abs(s[0]-s[1]))
else:
    for i in range(n):
        d = sum(s[:i + 1]) - sum(s[i + 1:])
        m = min(m, abs(d))
    print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
mi=10**15
s1=a[0]
for i in range(1,len(a)):
  s1+=a[i]
  s2=s-s1
  #print(s1,s2)
  mi=min([mi,abs(s1-s2)])
print(mi)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=input().split()
l=n - n %2-1
e=[i for i in a[l::-2]]  
o=[i for i in a[::2]]
e.extend(o)
if n % 2 ==0:
  print(*e)
else:
  print(*e[::-1])

Submission status: Wrong Answer

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

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

i=1

while i < n:
  x+=a[i]
  y-=a[i]
  m = min(abs(x - y),m)
  i+=1
print(m)

Submission status: Wrong Answer

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

B1 = A.copy()
B2 = [0]*n
B2[0] = B1[0]
A.reverse()
C1 = A
C2 = [0]*n
C2[0] = C1[0]

for i in range(1,n):
    B2[i] = B2[i-1] + B1[i]
    C2[i] = C2[i-1] + C1[i]
    
n_min = 1000000000
for i in range(n-1):
    d = abs(C2[i] - B2[-i])
    if n_min > d:
        n_min = d


print(n_min)

Submission status: Wrong Answer

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

B1 = A.copy()
B2 = [0]*n
B2[0] = B1[0]
A.reverse()
C1 = A
C2 = [0]*n
C2[0] = C1[0]

for i in range(1,n):
    B2[i] = B2[i-1] + B1[i]
    C2[i] = C2[i-1] + C1[i]
    
n_min = 1000000000
for i in range(n-1):
    d = abs(C2[i] - B2[n-2-i])
    if n_min > d:
        n_min = d


print(n_min)

Submission status: Wrong Answer

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

B1 = sorted(A)
B2 = [0]*n
B2[0] = B1[0]
C1 = sorted(A,reverse=True)
C2 = [0]*n
C2[0] = C1[0]

for i in range(1,n):
    B2[i] = B2[i-1] + B1[i]
    C2[i] = C2[i-1] + C1[i]

n_min = 10000000000
for i in range(n-1):
    d = abs(C2[i]-B2[n-2-i])
    if n_min >= d:
        n_min = d
print(n_min)

Submission status: Wrong Answer

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

B = sorted(A)

n_min = 10000000000    
for i in range(1,n):
    db = abs(sum(B[i:]) - sum(B[0:i]))
    if n_min > db:
        n_min = db

print(n_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ans = float("inf")
x = 0

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

print(ans)

Submission status: Wrong Answer

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

for i in range(1,n):
    snuke=sum(a[0:i])
    now=abs(X-2*snuke)
    if now<ans:
        ans=now
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):
    snuke=sum(a[0:i])
    raccoon=sum(a)-snuke
    if ans>abs(snuke-raccoon):
        ans=abs(snuke-raccoon)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(N):
    A.append(abs(B[i]))

A.sort()
A.reverse()

x=0
y=0

for i in range(len(A)):
    if x<=y:
        x=x+int(A[i])
    else:
        y=y+int(A[i])

print(abs(x-y))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:

num = int(input())

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

res = sum(cards)
res2 = 0

judge = float("inf")

if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in range(0, len(cards)):
        res -= cards[i]
        res2 += cards[i]
        div = abs(res - res2)
        judge = div if div < judge and i != len(cards) else judge

print(judge)

Submission status: Wrong Answer

Solution code:

num = int(input())

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

res = sum(cards)
res2 = 0

judge = float("inf")

if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in cards:
        res -= i
        res2 += i
        div = abs(res - res2)
        judge = div if div < judge else judge

print(judge)

Submission status: Wrong Answer

Solution code:

num = int(input())

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

res = sum(cards)
res2 = 0

judge = 2000000001

if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in cards:
        res -= i
        res2 += i
        div = abs(res - res2)
        judge = div if div < judge else judge

print(judge)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

x = a[0]
X = sum(a)
ans = 10 ** 10
for i in range(1, N):
    ans = min(ans, abs(X - 2 * x))
    x += a[i]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import bisect
import operator

N = int(input())
a = list(map(int, input().split()))
a.sort()


midv = (a[0] + a[-1]) // 2
mididx = bisect.bisect(a, midv)
x, y = sum(a[:mididx]), sum(a[mididx:])
maxv = abs(x - y)
preidx = mididx

if len(a) // 2 > mididx:
    func = operator.sub
    flag = False
else:
    func = operator.add
    flag = True

while True:
    tmp = abs(x - y)
    if maxv < tmp:
        break
    maxv = tmp
    if mididx == len(a) - 1 or mididx == 0:
        break

    if flag:
        x += a[preidx]
        y -= a[preidx]
    else:
        x -= a[preidx]
        y += a[preidx]
        
    preidx = mididx
    mididx = func(mididx, 1)
print(maxv)

Submission status: Wrong Answer

Solution code:
import bisect
import operator

N = int(input())
a = list(map(int, input().split()))
a.sort()

x, y = a[0], a[-1]

midv = (x + y) // 2
mididx = bisect.bisect(a, midv)
maxv = abs(sum(a[:mididx]) - sum(a[mididx:]))

if len(a) // 2 > mididx:
    func = operator.sub
else:
    func = operator.add

while True:
    tmp = abs(sum(a[:mididx]) - sum(a[mididx:]))
    if maxv < tmp:
        break
    maxv = tmp
    if mididx == len(a) - 1 or mididx == 0:
        break
    mididx = func(mididx, 1)
print(maxv)

Submission status: Wrong Answer

Solution code:
def abs(n):
	if n >= 0:
		return n
	else:
		return -n
		
n = int(input())
a = list(map(int,input().split()))
x = []
y = []
difference = []
total = 0
for i in range(n):
	total += a[i]
x.append(a[0])
y.append(total - a[0])
c = x[0] - y[0]
difference.append(abs(c))
if n % 2 != 0:
	n += 1
 
for i in range(1,n//2):
	x.append(x[i - 1] + a[i])
	y.append(total - x[i])
	b = x[i] - y[i]
	difference.append(abs(b))
difference.sort()
print(difference[0])

Submission status: Wrong Answer

Solution code:
def abs(n):
	if n >= 0:
		return n
	else:
		return -n
		
n = int(input())
a = list(map(int,input().split()))
x = []
y = []
difference = []
total = 0
for i in range(n):
	total += a[i]
x.append(a[0])
y.append(total - a[0])
c = x[0] - y[0]
difference.append(abs(c))
if n % 2 != 0:
	n += 1

for i in range(1,n//2):
	x.append(x[i - 1] + a[i])
	y.append(total - x[i])
	b = x[i] - y[i]
	print('x{0}'.format(x[i]))
	difference.append(abs(b))
difference.sort()
print(difference[0])

Submission status: Wrong Answer

Solution code:
def abs(n):
	if n >= 0:
		return n
	else:
		return -n
		
n = int(input())
a = list(map(int,input().split()))
x = []
y = []
difference = []
total = 0
for i in range(n):
	total += a[i]
x.append(a[0])
y.append(total - a[0])
c = x[0] - y[0]
difference.append(abs(c))
if n % 2 != 0:
	n += 1

for i in range(1,n//2 +1):
	x.append(x[i - 1] + a[i])
	y.append(total - x[i])
	b = x[i] - y[i]
	difference.append(abs(b))
difference.sort()
print(difference[0])

Submission status: Wrong Answer

Solution code:
def abs(n):
	if n >= 0:
		return n
	else:
		return -n
		
n = int(input())
a = list(map(int,input().split()))
x = 0
y = 0
difference = []
total = 0
for i in range(n):
	total += a[i]
if n % 2 != 0:
	n += 1

for i in range(1,n//2 +1):
	for k in range(i):
		x += a[k]
	y = total - x
	b = x - y
	difference.append(abs(b))
difference.sort()
print(difference[0])

Submission status: Wrong Answer

Solution code:
def abs(n):
	if n >= 0:
		return n
	else:
		return -n

n = int(input())
a = list(map(int,input().split()))
x = 0
y = 0
difference = []
total = 0
for i in range(n):
	total += a[i]
for i in range(1,n):
	for k in range(i):
		x += a[k]
	y = total - x
	b = x - y
	difference.append(abs(b))
difference.sort()
print(difference[0])