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 = 0
y = sum(a)
ans = float("inf")
for i in range(n):
    x += a[i]
    y -= a[i]
    if i == 0 or i == n:
        ans = min(ans, abs(x - y))
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(n, A):
    total = sum(A)
    x = A[0]
    ret = total
    for i in range(1, n - 1):
        x += A[i]
        y = total - x
        if abs(x - y) < ret:
            ret = abs(x - y)
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Wrong Answer

Solution code:
def solve(n, A):
    total = sum(A)
    tmp = 0
    x = 0
    ret = total
    for a in A:
        x += a
        y = total - x
        if abs(x - y) < ret:
            ret = abs(x - y)
    return ret

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

for i in range(1, n):
    sub -= 2 * a[i]
    if abs(sub) < asub:
        asub = abs(sub)
print(asub)

Submission status: Wrong Answer

Solution code:
n = int(input())
dList = list(map(int,input().split()))
sumX = sum(dList)
result = 10**9
for i in range(1,n):
  if result == 0:
    break
  tmp = abs(sumX - 2*sum(dList[:i]))
  if result > tmp:
    result = tmp

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
dList = list(map(int,input().split()))
sumX = sum(dList)

nMiIdx = 0
nMaIdx = n
minSum = 10**9
nT = 0
while True:
  nT = nT + (nMaIdx-nMiIdx)//2
#  print("nT",nT)
#  print("nMaIdx",nMaIdx)
#  print("nMiIdx",nMiIdx)
#  print("minSum",minSum)
  if nT == 0:
    break
  

  d = sumX - 2*sum(dList[:(nT)])
#  print("xI",nT-1)
#  print("x",sum(dList[:(nT)]))
#  print("xlist",(dList[:(nT)]))
#  print("y",sum(dList[(nT):]))
  
  if abs(d) == 0:
    minSum = abs(d)
    break
  elif minSum > abs(d):
    minSum = abs(d)
#  print("d",d) 
  if d > 0:
    nMaIdx = nMaIdx-nT
  elif d < 0:
    nMiIdx = nMiIdx+nT

print(minSum)

Submission status: Wrong Answer

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

nMiIdx = 0
nMaIdx = n
minSum = 10**9
nT = 0
while True:
  nT = nT + (nMaIdx-nMiIdx)//2
#  print("nT",nT)
#  print("nMaIdx",nMaIdx)
#  print("nMiIdx",nMiIdx)
#  print("minSum",minSum)
  if nT == 0:
    break
  

  d = sum(dList[:(nT)])-sum(dList[(nT):])
#  print("xI",nT-1)
#  print("x",sum(dList[:(nT)]))
#  print("xlist",(dList[:(nT)]))
#  print("y",sum(dList[(nT):]))
  
  if abs(d) == 0:
    minSum = abs(d)
    break
  elif minSum > abs(d):
    minSum = abs(d)
#  print("d",d) 
  if d > 0:
    nMaIdx = nMaIdx-nT
  elif d < 0:
    nMiIdx = nMiIdx+nT

print(minSum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

for i in range(n - 1):
    sub -= 2 * a[i]
    if abs(sub) < asub:
        asub = abs(sub)
print(asub)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
s = sum(a)
ans = 10 ** 18 + 101
cnt = 0
if n == 2:
    print(abs(a[0] - a[1]))
    exit()
for i in range(n):
    cnt += a[i]
    if n >= 1:
        ans = min(ans, abs(s - 2 * cnt))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

r = sum(a)
l = 0
sub = 10 ** 19 + 101
for i in range(n):
    r -= a[i]
    l += a[i]
    # print(l, r,sub)
    if n == 2:
        print(abs(r - l))
        exit()
    elif abs(r - l) > sub:
        print(tmp)
        exit()
    else:
        sub = min(sub, abs(r - l))
        tmp = abs(r - l)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
#A = [i*(10**3) for i in range(N)]
#A = [i for i in range(N)]

sum_a = sum(A)
ans = abs(2*A[0]-sum_a)
for i in range(2, math.ceil(N/2)):
        ans = min(ans, abs(2*sum(A[:i])-sum_a))
#sum_a = sum(A)
#ans = min([abs(2*sum(A[:i])-sum_a) for i in range(1, math.ceil(N/2))])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum_card = sum(a)
sum_harf = sum_card/2
sunuke = 0
arai = 0
min_diff = 10**12
if sum_card == 0:
    for i in range(n):
        sunuke += a[i]
        if sunuke == 0:
            ans = sunuke - a[i] -a[i]
    print(abs(ans))
elif sum_card < 0:
    for i in range(len(a)):
        sunuke += a[i]
        if sunuke < sum_harf:
            ans = sum_card -sunuke -a[i]
            break
    print(abs(ans))
else:
    for i in range(0,len(a)):
        sunuke += a[i]
        if sunuke > sum_harf:
            ans = sum_card - sunuke - a[i]
            break
    print(abs(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum_card = sum(a)
sum_harf = sum_card/2
sunuke = 0
arai = 0
min_diff = 10**12
if sum_card == 0:
    print(0)
elif sum_card < 0:
    for i in range(len(a)):
        sunuke += a[i]
        if sunuke < sum_harf:
            ans = sum_card -sunuke -a[i]
            break
    print(abs(ans))
else:
    for i in range(0,len(a)):
        sunuke += a[i]
        if sunuke > sum_harf:
            ans = sum_card - sunuke - a[i]
            break
    print(abs(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum_card = sum(a)
sunuke = 0
arai = 0
min_diff = 10**12
if n == 2:
    print(abs(a[0]-a[1]))
else:
    for i in range(1,len(a)-1):
        sunuke = sum(a[:i])
        arai = sum(a[i:])
        min_diff = abs(sunuke-arai)
    print(min_diff)

Submission status: Wrong Answer

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

v = sum(A) / 2
ctr = 0

for i in range(N):
	ctr += A[i]
	if ctr > v:
		if i == 0:
			print(abs(ctr - (sum(A) - ctr)))
		elif i == N - 1:
			print(abs(ctr - A[i] - (sum(A) - (ctr - A[i]))))
		else:
			print(min(abs(ctr - (sum(A) - ctr)), abs(ctr - A[i] - (sum(A) - (ctr - A[i])))))
		break
	elif ctr == v:
		print(0)
		break

Submission status: Wrong Answer

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

ans = 1000000000
if N == 2:
    ans = abs(a[0]-a[1])
    print(ans)
    exit()

for i in reversed(range(N)):
    backElements = total[-1] - total[i]
    sabun = abs(total[i] - backElements)
    if sabun == 0:
        continue
    ans = min(ans, sabun)
print(abs(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = list(map(int, input().split()))
arr = np.array(a)
res = np.cumsum(arr)

ans = 1000000000
for i in reversed(range(N)):
    backElements = res[-1] - res[i]
    sabun = abs(res[i] - backElements)
    if sabun == 0:
        continue
    ans = min(ans, sabun)
print(abs(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
b,i,c=10**9,1,True
while(i<n and c):
  p=sum(l[:i])
  q=sum(l[i:])
  if min(b,abs(p-q))!=abs(p-q):
    break
  else:
    b=min(b,abs(p-q))
    i+=1
print(b)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
b,i,c=10**9,1,True
while(i<n and c):
  p=sum(l[:i])
  q=sum(l[i:])
  c=min(b,abs(p-q))==abs(p-q)
  b=min(b,abs(p-q))
  i+=1
print(b)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
b,i=10**9,1
while(i<n):
  p=sum(l[:i])
  q=sum(l[i:])
  b=min(b,abs(p-q))
  i+=1
print(b)

Submission status: Wrong Answer

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)
print(cumArray)

ans = 10**12
for i in range(1, n):
    # print(i, cumArray[i], cumArray[n]-cumArray[i],
    #      abs(cumArray[n]-2*cumArray[i]))
    ans = min(ans, abs(cumArray[n]-2*cumArray[i]))

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)
# print(cumArray)

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

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)
#print(cumArray)

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

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)
# print(cumArray)

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

print(ans)

Submission status: Wrong Answer

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A=list(accumulate(A))
max_= -float("inf")

for a in A:
    max_=max(max_,abs(A[-1]-2*a))
print(max_)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    A.sort(reverse=True)

    a = A[0]
    b = A[1]

    for i in range(2, N):
        if A[i] > 0:
            if a > b:
                b += A[i]
            else:
                a += A[i]
        else:
            if a < b:
                b += A[i]
            else:
                a += A[i]

    print(abs(a - b))

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
SUM=sum(a)
sum_snuke = a[0]
sum_araisan = 0
answer = float('inf')

for i in range(n):
    sum_snuke += a[i]
    sum_araisan = SUM - sum_snuke
    # print(sum_snuke, sum_araisan)
    if answer >= abs(sum_snuke - sum_araisan):
        answer = abs(sum_snuke - sum_araisan)

print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
SUM=sum(a)
sum_snuke = 0
sum_araisan = 0
answer = float('inf')
for i in range(1, n):
    sum_snuke += a[i]
    sum_araisan = SUM - sum_snuke
    # print(sum_snuke, sum_araisan)
    if answer >= abs(sum_snuke - sum_araisan):
        answer = abs(sum_snuke - sum_araisan)

print(answer)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=float('INF')

for i in range(1,n-1):
    arai=sum(a)-snuke-a[i]
    
    if a[i]>=0:
        ans=min(ans, max(snuke,arai)-min(snuke,arai)-a[i])
    else:
        ans=min(ans,max(snuke,arai)+a[i]-min(snuke,arai))
    snuke+=a[i]

if n>2:
    print(abs(ans))
else:
    print(max(a)-min(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
snuke=a[0]
arai=sum(a)-a[0]
ans=float('INF')

for i in range(1,n-1):
    arai-=a[i]
    if a[i]>=0:
        ans=min(ans, max(snuke,arai)-min(snuke,arai)-a[i])
    else:
        ans=min(ans,max(snuke,arai)+a[i]-min(snuke,arai))
    snuke+=a[i]

if n>2:
    print(abs(ans))
else:
    print(max(a)-min(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 9999999
x = 0
for i in range(n - 1):
    x += a[i]
    y = sum(a) - 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 = 9999999
x = 0
for i in range(n - 1):
    x += a[i]
    y = sum(a[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 = 9999999
for i in range(n - 1):
    x = sum(a[:i+1])
    y = sum(a[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()))
ind = n - 1
y = a[ind]
x = 0
for i in range(n):
    if i == ind:
        break
    if x >= a[ind]:
        ind -= 1
        y += a[ind]
        x += a[i]
    elif x < a[ind]:
        x += a[i]
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ind = n - 1
y = a[ind]
x = 0
for i in range(n):
    if i == ind:
        break
    if x >= a[ind]:
        ind -= 1
        y += a[ind]
        x += a[i]
    elif x < a[ind]:
        x += a[i]
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
sum = 0
for i in range(N) :
    sum+=a[i]
ans = 200000000000
suma = 0
for i in range(N) :
    suma += a[i]
    d = abs(sum - 2 * suma)
    if i + 1 < N :
        ans = min(d,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC067c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def cum(array):
    result = [0]
    for i in range(len(array)):
        result.append(array[i]+result[i])
    return result


cumArray = cum(a)

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

print(ans)

Submission status: Wrong Answer

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


s = sum(a)
subsum = 0
res = 1001001001001001
for i in range(n-1):
    subsum += a[i]
    remain = s - subsum
    print(subsum, remain)
    res = min(res, abs(remain-subsum))

print(res)

Submission status: Wrong Answer

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

X = sum(a)
ans = 10 ** 9
x = 0
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()))

X = sum(a)

ans = 10 ** 9
x = 0
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()))

X = sum(a)

ans = 10 ** 9
x = 0
for i in range(n-1):
    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=[int(i) for i in input().split()]
l=[2*(10**5)]

for i in range(1,n):
  j=n-i
  x=sum(a[:i])
  y=sum(a[i:n])
  if abs(x-y)<l[-1]:
    l.append(abs(x-y))
l.sort()
print(l[0])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[i-1]+a[i])
#print(b)
ans=1000000
for i in range(n-1):
    ans=min(abs((b[-1]-b[i])-b[i]),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def nb(n,a,b,ho):
  #print(n,a,b,ho)
  if(b-a<=1):
    return min(abs(hoge[n]-2*hoge[a]),abs(hoge[n]-2*hoge[b]))
  c=(a+b)//2
  if(hoge[b]-2*hoge[c]>=0):
    return nb(n,c,b,ho)
  else:
    return nb(n,a,c,ho)


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


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

print(nb(n-1,0,n-1,hoge))

Submission status: Wrong Answer

Solution code:
def nb(n,a,b,ho):
  #print(n,a,b,ho)
  if(b-a<=1):
    return abs(hoge[n]-2*hoge[a])
  c=(a+b)//2
  if(hoge[b]-2*hoge[c]>=0):
    return nb(n,c,b,ho)
  else:
    return nb(n,a,c,ho)


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


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

print(nb(n-1,0,n-1,hoge))

Submission status: Wrong Answer

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

a.sort()

b = 0
c = sum(a)

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

print(ans)

Submission status: Wrong Answer

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

a.sort()
total = sum(a)

b = 0
c = total

ans = 10 ** 9
for i in range(n-1):
    b = b + a[i]
    c = total - b
    ans = min(ans, abs(b - c))

print(ans)

Submission status: Wrong Answer

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

a.sort()

b = []
for i in range(n-1):
    b.append(a[i+1] - a[i])

print(min(b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
import numpy
s = numpy.cumsum(A)
sA = s[-1]
ar = numpy.abs(sA-s-s)
print(min(ar))

Submission status: Wrong Answer

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

sa = sum(a)

ans = 10**18
for c in cumsum:
    ans = abs(sa-2*c)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
X = sum(A)
ans = 10 ** 6
x = 0
for i in range(N):
    x += A[i]
    if 0 < i < N-1:
        ans = min(ans, abs(X - 2 * x))
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
X = sum(A)
ans = 10 ** 9 + 7
x = 0
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:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(abs(A[0] - A[1]))
    exit()
a1, a2 = 0, 0
b1, b2 = 0, 0
for i in range(N//2):
    if a1 > b1:
        b1 += A[i]
    else:
        a1 += A[i]
for i in range(N//2):
    if a2 > b2:
        b2 += A[-i-1]
    else:
        a2 += A[-i-1]
print(min(abs(a1+a2 - b1-b2), abs(a1+b2 - b1-a2)))

Submission status: Wrong Answer

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

    b = 1e+9

    for j in range(n+1):
        if (abs(s[j] - (s[n] - s[j])) < b):
            b = abs(s[j] - (s[n] - s[j]))
    print(b)

Submission status: Wrong Answer

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

b = 1e+9

for j in range(n+1):
    if (abs(s[j] - (s[n] - s[j])) < b):
        b = abs(s[j] - (s[n] - s[j]))

print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = 0
y = [0]
j = 1
while(j < n+1):
    y.append(a[j-1] + y[j-1])
    j += 1
k = 0
while (y[k] < y[n]/2):
    k += 1
l,p = 0,n-1
o = []
m = []
while(l < k-1):
    o.append(a[l])
    l += 1
while(p >= k-1):
    m.append(a[p])
    p -= 1
print(sum(m) - sum(o))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
t = []
u = []
i = 0
y = [0]
j = 1
while(j < n+1):
    y.append(a[j-1] + y[j-1])
    j += 1
k = 0
while (y[k] < y[n]/2):
    k += 1
l,p = 0,n-1
o = []
m = []
while(l < k-1):
    o.append(a[l])
    l += 1
while(p >= k-1):
    m.append(a[p])
    p -= 1
print(sum(m) - sum(o))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
t = []
u = []
i = 0
while (sum(t)+a[i] < sum(a)/2):
    t.append(a[i])
    i += 1
while (i < n):
    u.append(a[i])
    i += 1
print(abs(sum(u) - sum(t)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

if diff < min_diff:
    min_diff = diff
print(min_diff)

Submission status: Wrong Answer

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

a_sum = sum(a)
x = 0
y = a_sum
min_diff = a_sum

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

print(min_diff)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 10**18
for i in range(1,n-1):
    can = abs(sum(A[:i]) - sum(A[i:]))
    if can <= ans:
        ans = can

print(ans)

Submission status: Wrong Answer

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

ans = 10**18
for i in range(n):
    can = abs(sum(A[:i]) - sum(A[i:]))
    if can <= ans:
        ans = can

print(ans)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(A))

acc_a

maxs = 100000000000
if N>2:
    for i in range(1,len(acc_a)-1):
        if abs((acc_a[-1] - acc_a[i])   - acc_a[i])< maxs:
            maxs=abs(acc_a[-1] - 2*acc_a[i])
else:
    maxs=abs(acc_a[0] - acc_a[1])

print(maxs)

Submission status: Wrong Answer

Solution code:

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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


# In[88]:


N=one_int()
A = many_int()


# In[89]:


import itertools as it


# In[90]:


acc_a = list(it.accumulate(sorted(A)))


# In[94]:


maxs = 100000000000
for i in range(0,len(acc_a)):
    if abs((acc_a[-1] - acc_a[i])   - acc_a[i])< maxs:
        maxs=abs(acc_a[-1] - 2*acc_a[i])


# In[95]:


print(maxs)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(sorted(A)))

maxs = 100000000000
for i in range(0,len(acc_a)-1):
    if abs((acc_a[-1] - acc_a[i])   - acc_a[i])< maxs:
        maxs=abs(acc_a[-1] - 2*acc_a[i])


print(maxs)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(sorted(A)))

maxs = 100000000
for i in range(0,len(acc_a)-1):
    if abs((acc_a[-1] - acc_a[i])   - acc_a[i])< maxs:
        maxs=abs(acc_a[-1] - 2*acc_a[i])


print(maxs)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(sorted(A)))

maxs = 100000000
for i in range(0,len(acc_a)-1):
    if abs(acc_a[-1] - 2*acc_a[i])< maxs:
        maxs=abs(acc_a[-1] - 2*acc_a[i])


print(maxs)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(sorted(A)))
rev_acc_a = list(it.accumulate(sorted(A,reverse=True)))

acc_a

if N>2:
    maxs = 100000000
    for i in range(0,len(acc_a)):
        if abs(acc_a[i]- rev_acc_a[i-1])< maxs:
            maxs=abs(acc_a[i]- rev_acc_a[i-1])
else:
    maxs=abs(A[0]-A[1])

print(maxs)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(A))
rev_acc_a = list(it.accumulate(sorted(A,reverse=True)))

acc_a

if N>2:
    maxs = 100000000
    for i in range(0,len(acc_a)):
        if abs(acc_a[i]- rev_acc_a[i-1])< maxs:
            maxs=abs(acc_a[i]- rev_acc_a[i-1])
else:
    maxs=abs(A[0]-A[1])

print(maxs)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
A = many_int()

import itertools as it

acc_a = list(it.accumulate(A))
rev_acc_a = list(it.accumulate(sorted(A,reverse=True)))

acc_a

if N>2:
    maxs = 100000000
    for i in range(0,len(acc_a)):
        print(acc_a[i], rev_acc_a[i-1])
        if abs(acc_a[i]- rev_acc_a[i-1])< maxs:
            maxs=abs(acc_a[i]- rev_acc_a[i-1])
else:
    maxs=abs(A[0]-A[1])

print(maxs)

Submission status: Wrong Answer

Solution code:
import sys

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

Sc = list()

dp = [10**9] * (n-1)
ep = [10**9] * (n-1)
s = sum(As)

if n-2 == 0:
    print(abs(As[0] - As[1]))
    sys.exit()

for i in range(n-2):
    if i == 0:
        dp[i] = As[i]
    else:
        dp[i] = dp[i-1] + As[i]
    ep[i] = abs(dp[i] - s + dp[i])

print(dp)
print(ep)
print(min(ep))

Submission status: Wrong Answer

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

Sc = list()

dp = [10**9] * n
ep = [10**9] * n
s = sum(As)


for i in range(n-1):
    if i == 0:
        dp[i] = As[i]
    else:
        dp[i] = dp[i-1] + As[i]
    ep[i] = abs(dp[i] - s + dp[i])

print(min(ep))