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: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = [0]
if (n == 2):
    printf(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: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
suma = a[0]
suma2 = sum(a)
for i in range(1,N-1):
    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: Runtime Error

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

memo = sum(a)

a=a[0]
b=memo-a[0]

ans = abs(a-b)
for i in range(1,n-1):
    a += a[i]
    b -= a[i]

    ans = min(ans,abs(a-b))
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
sticks = list(map(int, input().split()))
s = sum(sticks)

a = []
sum_i = 0
for i, v in enumerate(sticks):
  sum_i += v
  if i == 0:
    continue
  if i == len(sticks) - 1:
    continue
  a.append(abs(s - 2*sum_i))

print(min(a))

Submission status: Runtime Error

Solution code:
def examC():
    N = I()
    A = LI()
    sumA = [0]*N
    sumA[0] = A[0]
    for i in range(N-1):
        sumA[i+1] = sumA[i]+A[i+1]
    cur = bisect.bisect_left(sumA,sumA[N-1]//2)
    ans = abs(min(sumA[N-1] -sumA[cur]*2,sumA[cur+1]*2-sumA[N-1]))
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(1,N+1):
  S[i]=S[i-1]+a[i-1]
  
ans=floot("Inf")
for i in range(1,N):
  tmp=abs(S[N]-S[i])
  ans=min(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
I = map(int, input().split())
minX = 1000000
for i in range(len(I)):
  minX = min(minX, abs(sum(I[:-i]) - sum(I[-i:]) ) )
  
print(minX)

Submission status: Runtime Error

Solution code:
 int(input())
I = sorted(map(int, input().split()))
minX = 1000000
for i in range(len(I)):
  minX = min(minX, abs(sum(I[:-i]) - sum(I[-i:]) ) )
  
print(minX)

Submission status: Runtime Error

Solution code:
K = int(input())
I = sorted(map(int, input().split()))
minX = 1000000
for i in range(I):
  minX = min(minX, abs(sum(I[:-i]) - sum(I[-i:]) ) )
  
print(minX)

Submission status: Runtime Error

Solution code:
import math
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    ans =math.inf
    s=0
    rac=sum(a)
    for i in a[:-1]:
        s+=i
        rac-=i
        if abs(s-rac)<ans:
            ans = abs(s-rac)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())
x=a[0]
y=a[1:]
ans=abs(x-y)
for i in a[1:-1]:
  x+=i
  y-=i
  ans=min(ans,abs(x-y))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
S = sum(l)
for i in range(N):
  x = x - l[i]
  ans = min(ans, abs(x - (S - x)))
 
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
s = sum(l)
for i in range(N):
  x = x - l[i]
  ans = min(ans, abs(x - (S - x)))
 
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

*A,  = map(int, input().split())
A    = np.array(A)
min = float('INF')

for i in range(N-1):

    min_temp = (np.abs(np.sum(A)-2*np.sum(A[0:i+1]))
    if min_temp < min:
        min = min_temp

print(min)

Submission status: Runtime Error

Solution code:
 C - Splitting Pile
N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)//2
for i in range(1,N):
    if sum_s < tmp:
        sum_s += a[i]
    else:
        break
sum_a = sum(a) - sum_s
ans = abs(sum_s - sum_a)
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*100000
total=0
mini=1000000000000000000
for i in range(N):
    total+=A[i]
    B[i]=total

for i in range(N):
    if abs(B[i]-(B[N-1]-B[i]))<mini:
        mini=abs(B[i] - (B[N - 1] - B[i]))
print(mini)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*100000
total=0
mini=1000000000000000000
for i in range(N):
    total+=A[i]
    B[i]=total

for i in range(N-1):
    if abs(B[i]-(B[N-1]-B[i]))<mini:
        mini=abs(B[i] - (B[N - 1] - B[i]))
print(mini)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import sys
input = sys.stdin.readline


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

    SUM = sum(a)

    ans = sys.maxint
    for i in range(1, n):
        ans = min(ans, abs(2 * sum(a[:i]) - SUM))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def main(N,A):
    zenbu = sum(A)
    part_sum = [A[0]]
    ans = float("INF")
    for i in range(1,N): 
        print(part_sum,zenbu-part_sum[-1])
        ans = min(ans, abs(zenbu-2*part_sum[-1]))
        part_sum.append(part_sum[-1]+A[i])

    print(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input()]
aray,tmp,ans = sum(a),0,float('inf')
for i in a:
    tmp += a
    ans = min(ans,abs(tmp-aray))
print(ans)

Submission status: Runtime Error

Solution code:
right_list=[] #右に進む
left_list=[] #左に進む
diff_list=[] #差分

right_list.append(l[0])
left_list.append(l[n-1])

for i in range(1,n):
    right_list.append(right_list[i-1]+l[i])
    left_list.append(left_list[i-1]+l[n-1-i])

left_list.reverse()

for i in range(0,n-1):
    diff_list.append(abs(right_list[i]-left_list[i+1]))

print(min(diff_list))

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
x = 0
ABS = 0
min = -1
loop = 0
SUM = 0
for i in range(a):
    SUM += i

for i in range(N-1):
    for j in range(i + 1):
        x += a[j]
    else:
        ABS = abs(2*x - SUM)
        x = 0
        if (min == -1 or min > ABS):
            min = ABS

print(min)

Submission status: Runtime Error

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

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    ans = min(ans,abs(le-ri))
else:
    print(min(ans))

Submission status: Runtime Error

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

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    min(ans,abs(le-ri))
else:
    print(min(ans))

Submission status: Runtime Error

Solution code:
import bisect
n=int(input())
al=list(map(int,input().split()))
tl=al[:]
for i in range(1,n):
    tl[i]=(tl[i-1]+tl[i])
ta=bisect.bisect_left(tl,tl[-1]/2)
print(abs(al[ta+1]-al[ta]))

Submission status: Runtime Error

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

s = sum(a)

w = None
for i in a[:-1]:
  s -= 2 * a
  if w is None:
    w = s
  else:
    w = min(w, s)
print(w)

Submission status: Runtime Error

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math
import numpy as np


N = int(input())
An = list(map(int, input().split()))
sm = [0, sum(An)]

ans = abs(An[0] - sum(An[1:]))
for i in range(N-1):
  sm[0] += An[i]
  sm[1] -= An[i]
  ans = min(ans, abs(sm[0]-sm[1]))
print(ans)

Submission status: Runtime Error

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math
import numpy as np


N = int(input())
An = np.asarray(list(map(int, input().split())))
cumsum = np.cumsum(An)
sm = np.sum(An)

ans = 10**14+1
for i in range(N-1):
  ans = min(ans, abs(sm-2*cumsum[i]))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
res = []
for i in range(1,len(a)):
    res.append(abs(a[:i+1]-a[i:]))

print(min(res))

Submission status: Runtime Error

Solution code:
#普通にやるとTLE
n = int(input())

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

total = sum(a)
ans = float("inf")
for i in range(n-1):
  x += a[i]
  y = total - x
  if(abs(x-y) < ans):
    ans = abs(x-y)
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())

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

s = 0

for i in range(n):
    s += data[i]
    data[i] = s

a = data[-1]
res = math.inf
for i in range(n-1):
    res = min(res,abs(data[i]-(a-data[i])))
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a = sorted(a)
X = sum(a)

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

print(min(ans))

Submission status: Runtime Error

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

A_r = A[::-1]

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

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

Submission status: Runtime Error

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

min = B

for i in range(N-1):
     A += a[i]
     B -= a[i]
     
   if min > abs(A - B):
        min = abs(A - B)
    

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()], key=lambda x: abs(x))
ans = 0
pos = False
neg = False
while A:
    a = A.pop()
    if ans * a > 0:
        ans -= a
        neg = True
    else:
        ans += a
        pos = True
if pos & neg:
    print(abs(ans))
else:
    print(abs(A[0]-sum(A[1:])))

Submission status: Runtime Error

Solution code:
from _overlapped import NULL
n = int(input())
a = list(map(int,input().split()))
ans = NULL
for i in range(n):
    tmp = abs(sum(a[:i])-sum(a[i:]))
    if ans == NULL:
        ans = tmp
    if tmp < ans:
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    for i in range(N-1):
      	X = abs(X-2*l[i])
        ans.append(X)
    print(min(ans))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
res = []
for i in range(1, N-1):
    snk = sum(A[:i])
    arg = sum(A[i:])
    res.append(abs(snk-arg))
print(min(res))

Submission status: Runtime Error

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

a_sum = sum(a_list)
min_num = float("inf")
r = []

for i in range(1, N):
    if len(r) == 0:
        r.append(a_list[0])
    else:
        r.append(r[i-1] + a_list[i])

    x = r[i-1]
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)

Submission status: Runtime Error

Solution code:
a = int(input())

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

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

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

Submission status: Runtime Error

Solution code:
a = int(input())

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

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

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

Submission status: Runtime Error

Solution code:
a = int(input())

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

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

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

Submission status: Runtime Error

Solution code:
import math

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

total = sum(A)

ans = math.inf
nusuke = 0
for a in A[:-1]:
    nusuke += a
    ans = min(ans, abs(nusuke - (total - nusuke)))

print(ans)

Submission status: Runtime Error

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

sumdata = 0

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

mytotal = 0

for v in list(map(int, arr_data[1])):
    
    if mytotal + v > sumdata // 2:
        
        break
        
    else:
        
        mytotal += v
        
print(sumdata-mytotal-mytotal)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from itertools import accumulate
    from bisect import bisect_left

    n = int(input())
    a = sorted(list(map(int, input().split())))
    summed_a = list(accumulate(a))
    x = bisect_left(summed_a, max(summed_a) // 2)

    if x == n - 1:
        x -= 1
    elif x == 0:
        x += 1

    print(abs(max(summed_a) - 2 * summed_a[x]))

Submission status: Runtime Error

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-2ppp)
    if qqq > qo:
        qqq=qo
        
print(qqq)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = list(map(int, input().split()))
ans = math.inf
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def c_splitting_pile(N, A):
    # Aの要素の総和をX、カードの山の先頭i枚の総和をxとすると、
    # |y-x|=|X-2x|である。各iについてこの値を計算すればよい
    total = sum(A)
    ans = float('inf')
    s = 0
    for i in range(N-1):
        s += A[i]
        ans = min(ans, abs(total - s * 2))
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_splitting_pile(N, A)

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
if(n==2):
  mi=abs(a[0]-a[1])
else:
  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: Runtime Error

Solution code:
def search(ans, s, ar, si = 0, ari = 0):
    if si+ari == n:
        if not(ari == 0) and not(si == 0):
            ans.append(abs(sum(s)-sum(ar)))
        return

    s.append(a[si+ari])
    search(ans,s,ar,si+1,ari)
    s.pop()

    ar.append(a[si+ari])
    search(ans,s,ar,si,ari+1)
    ar.pop()

n = int(input())
a = list(map(int,input().split()))
ans = []
s = []
ar = []
search(ans,s,ar)
print(min(ans))

Submission status: Runtime Error

Solution code:
import math

num = int(input())

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

res = sum(cards)
res2 = 0

judge = math.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: Runtime Error

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
if n % 2 != 0:
	n += 1

for i in range(n):
	total += a[i]
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: Runtime Error

Solution code:
~
"arc078_a.py" 13L, 193C                                       1,1          全て
N = int(input())
a = [int(n) for n in input().split()]

x = 0
y = sum(a)
res = 1000000000000000

for i in range(N-1):
  x += a[i]
  y -= a[i]
  if res > abs(x-y):
    res = abs(x-y)
print(res)

Submission status: Runtime Error

Solution code:
 ~
"arc078_a.py" 13L, 193C                                       1,1          全て
N = int(input())
a = [int(n) for n in input().split()]

x = 0
y = sum(a)
res = 1000000000000000

for i in range(N-1):
  x += a[i]
  y -= a[i]
  if res > abs(x-y):
    res = abs(x-y)
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
card = map(int,input().split(" "))

all = 0
for i in card:
    all += i

a = all
ab = all
for i in range(len(card),-1):
    b -= card[i]
    if abs(a - b) > ab:
        break
    a,ab = b,abs(a - b)
print(ab)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 
n = int(input())
a =list(map(int, input().split()))

N = sum(a)
r = float('inf')
x = 0

for i in range(N-1):
    x += a[i]
    y = N - x
    if r > abs(x -y):
        r = abs(x -y)
print(r)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
result = abs(sum(a[0:1]) - sum(a[1:]))
for i in range(1:n-1):
    d = abs(sum(a[0:i+1]) - sum(a[i+1:]))
    if d<result:
        result = d
print(result)

Submission status: Runtime Error

Solution code:
import math

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

l = 0
r = sum(a)

d = math.inf

for i in range(n - 1):
    l += a[i]
    r -= a[i]
    d = min(d, abs(l - r))

print(d)

Submission status: Runtime Error

Solution code:
num_cards = int(input())
str_value_of_cards_list = input().split
value_of_cards_list = [int(i) for i in str_value_of_cards_list]
 
num_A = 0
num_B = 0
a =0
 
while(is_yet_in):
    for num_card in range(num_cards):
        if num_A - num_B > 0:
            a = num_card
            is_yet_in = false
            break
        for i in value_of_cards_list[:num_card]:
            num_A += i
            
        for i in value_of_cards_list[num_card]:
            num_B += i
print(a)

Submission status: Runtime Error

Solution code:
num_cards = int(input())
str_value_of_cards_list = input().split
value_of_cards_list = [int(i) for i in str_value_of_cards_list]
 
num_A = 0
num_B = 0
a =0
 
while():
    for num_card in range(num_cards):
        if num_A - num_B > 0:
            a = num_card
            break:
        for i in value_of_cards_list[:num_card]:
            num_A += i
            
        for i in value_of_cards_list[num_card]:
            num_B += i
print(a)

Submission status: Runtime Error

Solution code:
nums = [int(x) for x in input().split()]
N = nums[0],nums[1]
A = [int(x) for x in input().split()]
X = sum(A)
MIN = 10**8

for i in range(N):
    s = A[0:i]
    MIN = (MIN,abs(X - 2*sum(s)))
print(MIN)

Submission status: Runtime Error

Solution code:
nums = [int(x) for x in input().split()]
N = nums[0],nums[1]
A = [int(x) for x in input().split()]
X = sum(A)
MIN = 10**8

for i in range(N):
    s = [0:i]
    MIN = (MIN,abs(X - 2*sum(s)))
print(MIN)

Submission status: Runtime Error

Solution code:
n = int(input())
arr = input().split()
ans = []
for i in range(n):
    arr[i] = int(arr[i])
x = 0
y = sum(arr)
for i in range(n):
    if x <= y:
        x += arr[i]
        y -= arr[i]
        ans.append(x - y)
ans = map(abs,ans)
print(min(ans))

Submission status: Runtime Error

Solution code:
num_cards = int(input())
str_value_of_cards_list = input().split
value_of_cards_list = [int(i) for i in str_value_of_cards_list]

num_A = 0
num_B = 0
a =0

while():
    for num_card in range(num_cards):
        if num_A - num_B > 0:
            a = num_card
            break:
        for i in value_of_cards_list[:num_cards]:
            num_A += i
            
        for i in value_of_cards_list[num_cards]:
            num_B += i
print(a)

Submission status: Runtime Error

Solution code:
n=input()
a=[];
for i in range(n): a.append(input())
for i in range(n-1): a[i+1]=a[i+1]+a[i]
p=1
q=n-1
while q-p>1:
      if a[n]-2*a[(q+p)/2]>0 p=(p+q)/2
      else q=(p+q)/2

print(min(abs(a[n]-2*a[p]),abs(a[n]-2*a[q])))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

ls = []
A = sum(ax[:1])
B = sum(ax[1:])

for i in range(2, N):
    sub = abs(A-B)
    print(sub)
    ls.append(sub)
    if(sub is 0):
        break
    A -= ax[i]
    B += ax[i]

print(sorted(ls)[0])

Submission status: Runtime Error

Solution code:
n = int(input())
arr = input().split()
ans = []
for i in range(n):
    arr[i] = int(arr[i])
x = 0
y = sum(arr)
for i in range(n):
    if x <= y:
        x += arr[i]
        y -= arr[i]
        ans.append(abs(x - y))
print(min(ans))

Submission status: Runtime Error

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

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

L = [0] * N
L[0] = a[0] - sum(a[1 : ])

if N == 2 : 
    print(abs(a[0] - a[1]))
else : 
    MIN = float("inf")
    for i in range(1 , N - 1 ) : 
        L[i] = L[i - 1] + 2 * a[i]
        if L[i] * L[i - 1] <= 0 : 
            if MIN > min( abs(L[i]) , abs(L[i - 1])) : MIN = min( abs(L[i]) , abs(L[i - 1]))

print(MIN)