Problem:


Score: 200 points

Problem Statement

Takahashi, who works at DISCO, is standing before an iron bar.
The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.

Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length.
However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:

Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).

Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.

Find the minimum amount of money needed before cutting the bar into two parts with the same length.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 2020202020

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.

Sample Input 1

3
2 4 3

Sample Output 1

3

The initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi can cut the bar equally after doing the following operations for 3 yen:

Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].

Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].

Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.

Sample Input 2

12
100 104 102 105 103 103 101 105 104 102 104 101

Sample Output 2

0



Sample input:
3
2 4 3


Sample output:
3

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    mod=10**9+7

    for i in range(n):
        if i==0:
            left=sum(numbers[:i])%mod
            right=sum(numbers[i:])%mod
            continue
        else:
            if abs(right-left)%mod > abs(sum(numbers[i:]) -sum(numbers[:i]))%mod:
                left=sum(numbers[:i])%mod
                right=sum(numbers[i:])%mod
    print(abs(right-left))

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
half_a = sum_a // 2
total = 0
ans = 0
for num in a:
    total += num
    if total >= half_a:
        ans = min(total - half_a, abs(total - num - half_a))
        if sum_a % 2 == 1:
            ans += 1
        break
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
S = sum(nums)
half = 0
for num in nums:
  half += num
  if half*2 >= S:
    answer = min(half-S//2, S//2-half+num)
    if S%2 != 0:
      answer += 1
    print(answer)
    exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
S = sum(nums)
print(S)
half = 0
for num in nums:
  half += num
  if half*2 >= S:
    answer = min(half-S//2, S//2-half+num)
    if S%2 != 0:
      answer += 1
    print(answer)
    exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
m=sum(a)
if m%2==1:
    ans=1
    m-=1
else:
    ans=0
a.insert(0,0)
b=[0]
c=[]
for l in range(n):
    b.append(b[l]+a[l+1])
for l in range(n):
    c.append(abs(m/2-b[l+1]))
print(int(min(c)+ans))

Submission status: Wrong Answer

Solution code:
N ,*A  = map(int,open(0).read().split())

L = [0 for i in range(N+1)]
D = [0 for i in range(N)]

for i,a in enumerate(A,1):
  L[i] = L[i-1] + a
for i in range(N):
  D[i] = L[-1]-L[i]
#L.pop(0)
  
print(L)
print(D)
ans = 1e19
for i in range(N):
  #print(L[i],D[i],L[i]-D[i])
  ans = min(abs(L[i]-D[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()))
total = sum(A)
total *= 2
mindif = 1e12
sub = 0
for i in range(N):
    sub += 2 * A[i]
    dif = abs(total//2-sub)
    if dif < mindif:
        mindif = dif
    else:
        break
print(mindif)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
left=0
l1=0
r1=0
right=0
for i in range(n//2):
  left+=a[i]
  if a[i]==1:
    l1+=1
  right+=a[-i-1]
  if a[-i-1]==1:
    r1+=1
  
if n%2!=0:#odd
  if left<right:
    left+=a[n//2]
  else:right+=a[n//2]

if abs(left-right)<=abs(right-left):
  if abs(left-right)>l1:
    b=abs(right-left)
  else:
    b=abs(left-right)
if abs(right-left)<=abs(left-right):
  if abs(right-left)>r1:
    c=abs(left-right)
  else:
    c=abs(left-right)
    
print(min(b,c))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
left=0
right=0
for i in range(n//2):
  left+=a[i]
  right+=a[-i-1]
  
if n%2!=0:#odd
  if left<right:
    left+=a[n//2]
  else:right+=a[n//2]

print(min(abs(left-right),abs(right-left)))

Submission status: Wrong Answer

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

from itertools import accumulate

tot=sum(l)
ans=10**9+7
for i in list(accumulate(l)):
    if i <= tot//2:
        ans=min(ans, abs(tot-(i*2)))


for i in list(accumulate(l[::-1])):
    if i <= tot//2:
        ans=min(ans, abs(tot-(i*2)))

print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate

tot=sum(l)
ans=10**9+7
for i in list(accumulate(l)):
    if i <= tot//2:
        ans=min(ans, abs(tot-(i*2)))


for i in list(accumulate(l[::-1])):
    if i <= tot//2:
        ans=min(ans, abs(tot--(i*2)))

print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate

tot=sum(l)
ans=10**9+7
for i in list(accumulate(l)):
    ans=min(ans, abs(tot-(i*2)))


for i in list(accumulate(l[::-1])):
    ans=min(ans, abs(tot--(i*2)))

print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate
cum=list(accumulate(l))

tot=sum(l)
ans=10**9+7
for i in cum:
    ans=min(ans, abs(tot-i*2))
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
cumsum = list(accumulate(a))
total = cumsum[-1]

ans = 10*20
for left in cumsum:
    right = total - left
    ans = min(ans, abs(left - right))

print(ans)

Submission status: Wrong Answer

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

sumA = sum(A)

cum=[0]
for i in range(N):
  cum.append(cum[-1]+A[i])

if sumA%2 == 0:
  print(min([abs(cum[i] - sumA//2) for i in range(N)]))
  exit()
  
res = [cum[i] - (sumA+1)//2 for i in range(N)]
#res = [cum[i] - sumA//2 for i in range(N)]
res1 = [-res[i] if res[i]<0 else res[i]+2 for i in range(N)]
res2 = [res[i]+1+2 if res[i]>0 else -res[i] for i in range(N)]

print(min(min(res1),min(res2)))

Submission status: Wrong Answer

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

sumA = sum(A)

cum=[0]
for i in range(N):
  cum.append(cum[-1]+A[i])

if sumA%2 == 0:
  print(min([abs(cum[i] - sumA//2) for i in range(N)]))
  exit()
  
res = [cum[i] - (sumA+1)//2 for i in range(N)]
#res = [cum[i] - sumA//2 for i in range(N)]
print(res)
res1 = [-res[i] if res[i]<0 else res[i]+2 for i in range(N)]
res2 = [res[i]+1+2 if res[i]>0 else -res[i] for i in range(N)]

print(min(min(res1),min(res2)))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    total_length = sum(a_list)

    accum_length = 0
    for i in range(n):
        accum_length += a_list[i]
        if 2 * accum_length >= total_length:
            if i == n - 1:
                ans = 2 * a_list[i] - accum_length
                break
            else:
                ans = 2 * accum_length - total_length
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    total_length = sum(a_list)

    accum_length = 0
    for a in a_list:
        accum_length += a
        if 2 * accum_length >= total_length:
            ans = 2 * accum_length - total_length
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選: B – Iron Bar Cutting

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

answer = 99999
for i in range(1, N):
    answer = min(answer, abs(sum(A[0:i]) - sum(A[i:N])))

print(answer)

Submission status: Wrong Answer

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


for i in range(1, N):
  x = abs(sum(A[:i]) - sum(A[i:]))
  if x < ans:
    ans = x
print(ans)

Submission status: Wrong Answer

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

N=int(input())
A=list(map(int,input().split()))
total = sum(A)
mindif = 1e12
sub = 0
for i in range(N):
    sub += A[i]
    dif = abs(total-sub-sub)
    if dif < mindif:
        mindif = dif
    else:
        break
print(mindif)

Submission status: Wrong Answer

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

n = N // 2
fsum = 0
bsum = 0
for i in range(n):
    fsum += A[i]
    bsum += A[N - 1 - i]
    print(fsum, bsum)

ans = 0
if N % 2 == 0:
    ans = abs(fsum - bsum)

else:
    if fsum <= bsum:
        fsum += A[N // 2]
    else:
        bsum += A[N//2]
    ans = abs(fsum - bsum)

print(ans)

Submission status: Wrong Answer

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

sum1 = 0
count = 0
total_length = sum(a)

for i in range(len(a)):
    sum1 += a[i]
    if sum1 >= total_length / 2:
        count1 = sum1 - sum(a[i + 1:])
        count2 = sum1 - a[i] - sum(a[i:])
        if count1 <= count2:
            count = abs(count1)
        else:
            count = abs(count2)
        break
print(count)

Submission status: Wrong Answer

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

l = sum(a)
halfp = 0
for i in range(n):
    if sum(a[:i+1])>= l/2:
        halfp = i
        break

print(int((sum(a[:halfp+1])-l/2)*2))

Submission status: Wrong Answer

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

sum1 = 0
count = 0
total_length = sum(a)

for i in range(len(a)):
    sum1 += a[i]
    if sum1 >= total_length / 2:
        count = sum1 - sum(a[i + 1:])
        break
print(count)

Submission status: Wrong Answer

Solution code:
#B - Iron Bar Cutting
import bisect
N = int(input())
A = list(map(int,input().split()))

length = []
cnt = 0
for i in A:
    cnt += i
    length.append(cnt)
trg_idx_l = bisect.bisect_left(length,length[-1]//2)
if length[trg_idx_l] == length[-1]:
    ans = A[-1]-A[-2]*2
else:
    # length[-1] - ans = 2*(length[target] - ans)
    ans = 2*length[trg_idx_l] - length[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
#B - Iron Bar Cutting
import bisect
N = int(input())
A = list(map(int,input().split()))

length = []
cnt = 0
for i in A:
    cnt += i
    length.append(cnt)
    
trg_idx_l = bisect.bisect_left(length,length[-1]//2)
trg_idx_r = bisect.bisect_right(length,length[-1]//2)
# length[-1] - ans = 2*(length[target] - ans)
ans_l = 2*length[trg_idx_l] - length[-1]
ans_r = 2*length[trg_idx_r] - length[-1]
ans = min(ans_l,ans_r)
print(ans)

Submission status: Wrong Answer

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

length = []
cnt = 0
for i in A:
    cnt += i
    length.append(cnt)
    
target_idx = bisect.bisect_left(length,length[-1]//2)

# length[-1] - ans = 2*(length[target] - ans)
ans = 2*length[target_idx] - length[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = (int)(input())
a = list(map(int, input().split(" ")))
total = sum(a)
temp = 0
for i in range(n):
  temp += a[i]
  if temp >= total / 2:
    break
print(temp - (total - temp))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
harf=sum(a)//2
l,r,i=0,a[0],0
while r<harf:
    i+=1
    l=r
    r+=a[i]
print(min(harf-l,r-harf))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

count = 0
ironbar = list(accumulate(A))

i = 0
j = len(A) - 1

while i + 1 < j:
    left = ironbar[i]
    right = ironbar[-1] - ironbar[i]
    if right <= left:
        j = (i+j) // 2
    else:
        i = (i+j) // 2

# iかjが正解
i_bar = abs(ironbar[i] - (ironbar[-1] - ironbar[i]))
j_bar = abs(ironbar[j] - (ironbar[-1] - ironbar[j]))

print(min(i_bar, j_bar))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

count = 0
ironbar = list(accumulate(A))

i = 0
j = len(A) - 1

while i + 1 < j:
    left = ironbar[i]
    right = ironbar[j] - ironbar[i]
    if left > right:
        j = (i+j) // 2
    elif left < right:
        i = (i+j) // 2
    else:
        print(0)
        exit()

left = ironbar[i]
right = ironbar[j] - ironbar[i]

print(abs(left-right))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

count = 0
ironbar = list(accumulate(A))

i = 0
j = len(A) - 1

while i + 1 < j:
    left = ironbar[i]
    right = ironbar[j] - ironbar[i]
    if left > right:
        j = (i+j) // 2
    elif left < right:
        i = (i+j) // 2
    else:
        print(0)
        exit()

print(abs(ironbar[i]-ironbar[j]))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

count = 0
ironbar = list(accumulate(A))

print(ironbar)

i = 0
j = len(A) - 1

while i + 1 < j:
    left = ironbar[i]
    right = ironbar[j] - ironbar[i]
    if left > right:
        j = (i+j) // 2
    elif left < right:
        i = (i+j) // 2
    else:
        print(0)
        exit()

print(abs(ironbar[i]-ironbar[j]))

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())

s = sum(a)
if n & 1:
    left1 = sum(a[:n // 2])
    right1 = s - left1
    left2 = sum(a[:n // 2 + 1])
    right2 = s - left2
    print(min(abs(left1 - right1), abs(left2 - right2)))
else:
    left = sum(a[:n // 2])
    right = sum(a[n // 2:])
    print(abs(left - right))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
lis = list(map(int, input().split()))

ans = 0

if n % 2 == 0:
    tmp = abs(sum(lis[:n//2]) - sum(lis[n//2:]))
    print(tmp)
else:
    left = math.floor(n/2)
    right = math.ceil(n/2)
    l_lis = sum(lis[:left])
    r_lis = sum(lis[right:])

    if l_lis >= r_lis:
        t = abs(l_lis-(r_lis+lis[left]))
    else:
        t = abs((l_lis+lis[left]) - r_lis)
    
    print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = A
S = sum(A)
B.reverse()
cum1 = [0]*(N)
cum2 = [0]*(N)
now1 = 0
for i in range(N):
  now1 += A[i]
  cum1[i] = now1
  cum2[i] = S-now1
minimum = 10**9
for i in range(N):
  if abs(cum1[i]-cum2[i]) < minimum:
    minimum = abs(cum1[i]-cum2[i])
print(minimum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = A
B.reverse()
cum1 = [0]*(N)
cum2 = [0]*(N)
now1 = 0
for i in range(N):
  now1 += A[i]
  cum1[i] = now1
  cum2[i] = sum(A)-now1
minimum = 10**9
for i in range(N):
  if abs(cum1[i]-cum2[i]) < minimum:
    minimum = abs(cum1[i]-cum2[i])
print(minimum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
B = A
B.reverse()
cum1 = [0]*(N)
cum2 = [0]*(N)
now1 = 0
for i in range(N):
  now1 += A[i]
  cum1[i] = now1
  cum2[i] = sum(A)-now1
minimum = 10**9
for i in range(N):
  if abs(cum1[i]-cum2[i]) < minimum:
    minimum = abs(cum1[i]-cum2[i])
print(minimum)

Submission status: Wrong Answer

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

if cum[-1]%2==0 and cum[-1]//2 in cum:
    print(0)
    exit()

mid = -(-cum[-1]//2)

i=0
while True:
    if cum[i] >= mid:
        x = i
        break
    else: i+=1

j=0
while True:
    if (cum[x]-j)*2 == cum[-1]-j:
        print(j)
        break
    else: j+=1

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
a=list(map(int,input().split()))
cumsum=[0]+list(itertools.accumulate(a))
sum_num=sum(a)
ans=10**9
for i in range(1,n):
    yen=abs(cumsum[i]-(sum_num-cumsum[i]))
    if yen<ans:
        ans=yen
print(ans)

Submission status: Wrong Answer

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

SUM=sum(a)
for i in range(n):
  diff[i]=s[i]-(SUM-s[i])
ans=[diff[i] for i in range(n) if diff[i]>=0]
#print(diff)
print(min(ans))

Submission status: Wrong Answer

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

    l = r = ans = 0
    if N % 2 == 0:
        l = sum(A[:len(A)//2])
        r = sum(A[len(A)//2:])
        ans = abs(l - r)

    else:
        l = sum(A[:len(A)//2])
        r = sum(A[len(A)//2+1:])
        m = A[len(A)//2]
        ans = m + min(l, r) - max(l, r)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin


n = int(stdin.readline().strip())
a_lst = [int(x) for x in stdin.readline().strip().split()]

pos = len(a_lst) // 2
min_diff = 20202020201

while(True):
  left = sum(a_lst[:pos])
  right = sum(a_lst[pos:])
  diff = right - left
  
  if min_diff > abs(diff): min_diff = abs(diff)
  else: break
  
  if diff > 0: pos += 1
  elif diff < 0: pos -= 1
    
print(min_diff)

Submission status: Wrong Answer

Solution code:
import sys
import collections
import bisect


def main():
    n = int(input())
    AList = list(map(int, input().split()))
    sumAList = AList
    sumA = sum(AList)
    for i in range(n):
        if i != 0:
            AList[i] = AList[i] + AList[i - 1]
        if sumA - AList[i] <= AList[i]:
            print(abs(sumA - 2 * AList[i]))
            return

    print(sumAList)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選
# B - Iron Bar Cutting

import bisect

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

l=sum(A)//2
m=sum(A)%2

aA=[0]
for i in range (N):
    aA.append(A[i]+aA[-1])

t=bisect.bisect_left(aA,l)


print(abs(aA[t]-l)+m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
t = [0]
for i in range(n):
    t.append(t[i] + a[i])
t.pop(0)
p = t[-1] // 2
if p in t:
    print(0)
else:
    for i in range(n):
        if p < t[i]:
            print(abs(sum(a[0:i+1]) - sum(a[i+1:n])))
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
t = [0]
for i in range(n):
    t.append(t[i] + a[i])
t.pop(0)
p = t[-1]
m = 0
for i in range(n):
    if p // 2 <= t[i]:
        print(abs(sum(a[0:i+1]) - sum(a[i+1:n])))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
t = [0]
for i in range(n):
    t.append(t[i] + a[i])
t.pop(0)
p = t[-1]
m = 0
if p % 2 != 0:
    m += 1
    p -= 1
p = p // 2
if p in t:
    print(m)
else:
    for i in range(n):
        if t[i] > p:
            j = i
            break
    print(min(m + (t[j] - p),m + (p - t[j-1])))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect

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

acc = list(accumulate(a))

idx = bisect.bisect_left(acc,acc[-1]//2)
#print(idx)

print(abs((acc[-1] - acc[idx] ) - acc[idx]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = n//2
L = sum(a[0:m])
R = sum(a[m:n])
L2 = sum(a[0:n-m])
R2 = sum(a[n-m:n])
print(min(abs(L-R),abs(L2-R2)))

Submission status: Wrong Answer

Solution code:
import bisect


n = int(input())
la = [int(w) for w in input().split()]
la_sum = [0]*(n)
ans = 10**10

la_sum[0] = la[0]
for i in range(1, n):
    la_sum[i] = la_sum[i-1] + la[i]

p = bisect.bisect_left(la_sum, la_sum[-1]/2)

for i in range(p, n):
    l = la_sum[i]
    r = la_sum[-1]-la_sum[i]
    d = abs(l-r)
    ans = min(ans, d)
print(ans)

Submission status: Wrong Answer

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

ans = 10**10
for i in range(0, N):
    num0 += a[i]
    num1 -= a[i]
    if ans > abs(num1-num0):
        ans = abs(num1-num0)
    else:
        break
print(ans)

Submission status: Wrong Answer

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

ans = 10**10
for i in range(1, N+1):
    num = abs(sum(a[:i])-sum(a[i:]))
    if ans > num:
        ans = num
    else:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    sumA = sum(a)//2
    count = 0
    count1 = 0
    count2 = -1
    for i in a:
        count +=i
        if count <= sumA:
            count1=count
        if count >= sumA and count2 ==-1:
            count2 = count
    odd = 0
    if sum(a) %2 ==1:
        odd+=1
    print(min(sumA-count1,count2-sumA) + odd)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    cumsumA = [0] * (N + 1)
    cumsumB = [0] * (N + 1)
    for i in range(N):
        cumsumA[i + 1] = cumsumA[i] + A[i]
        cumsumB[N - i - 1] = cumsumB[N - i] + A[N - i - 1]
    minA = 10**9
    for i in range(N + 1):
        minA = min(minA, abs(cumsumA[i] - cumsumB[i]))
    print(minA)


resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
A=np.array(list(map(int, input().split())))
S=sum(A)
X=A[0]
ans=abs(S-X)
for i in range(1,N-1):
  X+=A[i]
  ans=min(ans,abs(S-X))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_left

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

cum_A = np.cumsum(A)
median = sum(A) / 2
idx = bisect_left(cum_A, median)

# print(idx)
if idx == N - 1:
    right = A[-1]
else:
    right = cum_A[-1] - cum_A[idx]
ans = abs(cum_A[idx] - right)
# print(cum_A, idx, right)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_left

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

cum_A = np.cumsum(A)
median = sum(A) / 2
idx = bisect_left(cum_A, median)

# print(idx)
right = cum_A[-1] - cum_A[idx]
ans = abs(cum_A[idx] - right)
print(ans)

Submission status: Wrong Answer

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

cum_A = [A[0]] * N
for i in range(1, N):
    cum_A[i] = cum_A[i - 1] + A[i]

half = cum_A[-1] // 2
for h in range(N):
    if cum_A[h] >= half:
        break

left = cum_A[h]
right = cum_A[-1] - cum_A[h]

print(left - right)

Submission status: Wrong Answer

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

x = n//2
if sum(a)/2 == sum(a[:(n//2)]):
  print(0)
elif sum(a)/2 >= sum(a[:(n//2)]):
  while sum(a)/2 >= sum(a[:x]):
    x += 1  
  print(min(abs(2*sum(a[:x])-sum(a)), abs(2*sum(a[:x-1])-sum(a))))
else:
  while sum(a)/2 <= sum(a[:x]):
    x -= 1
  print(min(abs(2*sum(a[:x])-sum(a)), abs(2*sum(a[:x-1])-sum(a))))

Submission status: Wrong Answer

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

ans = (sum(a)%2) * 2

print(ans)

Submission status: Wrong Answer

Solution code:
## B - Iron Bar Cutting
N = int(input())
A = list(map(int, input().split()))
val = sum(A)//2
tmp = 0
for n in range(N):
    tmp += A[n]
    if tmp >= val:
        print( min( [ abs(sum(A[n+1:]) - tmp ), abs(sum(A[n:]) - tmp - A[n]) ] ) )
        break

Submission status: Wrong Answer

Solution code:
## B - Iron Bar Cutting
N = int(input())
A = list(map(int, input().split()))
val = sum(A)//2
tmp = 0
for a in A:
    tmp += a
    if tmp >= val:
        print(abs(sum(A) - 2*tmp ))
        break

Submission status: Wrong Answer

Solution code:
## B - Iron Bar Cutting
N = int(input())
A = list(map(int, input().split()))
ans = abs(sum(A[:N//2]) - sum(A[N//2:]))
if ans == 0:
    print(0)
else:
    if sum(A[:N//2]) < sum(A[N//2:]):
        for n in range(N//2,N):
            tmp = abs(sum(A[:n]) - sum(A[n:]))
            if ans >= tmp:
                ans = tmp
            else:
                break
    else:
        for n in range(N//2,-1,-1):
            tmp = abs(sum(A[:n]) - sum(A[n:]))
            if ans > tmp:
                ans = tmp
            else:
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    a1 = A[:N//2]
    a2 = A[N//2:]
    b1 = A[:N//2+1]
    b2 = A[N//2+1:]
    if N%2 == 0:
        print(abs(sum(a1) - sum(a2)))
    else:
        if A[0] <= A[-1]:
            print(abs(sum(b1) - sum(b2)))
        if A[0] > A[-1]:
            print(abs(sum(a1) - sum(a2)))
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    if N%2 == 0:
        print(abs(sum(A[:N//2]) - sum(A[N//2:])))
    else:
        if A[0] <= A[-1]:
            print(abs(sum(A[:(N+1)//2]) - sum(A[(N+1)//2:])))
        if A[0] > A[-1]:
            print(abs(sum(A[:(N-1)//2]) - sum(A[(N-1)//2:])))
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    if N%2 == 0:
        print(abs(sum(A[:N//2]) - sum(A[N//2:])))
    else:
        if A[0] <= A[-1]:
            print(abs(sum(A[:N//2+1]) - sum(A[N//2+1:])))
        if A[0] > A[-1]:
            print(abs(sum(A[:N//2]) - sum(A[N//2:])))
resolve()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    half_length = sum(a) / 2 

    sum_peace_1 = 0
    idx = -1
    for i in range(n):
        sum_peace_1 += a[i]

        if half_length <= sum_peace_1:
            idx = i
            break

    sum_peace_2 = 0
    for i in range(idx+1, n):
        sum_peace_2 += a[i]
    
    print(abs(sum_peace_1-sum_peace_2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
ruiseki = [0]+list(itertools.accumulate(A))
i = bisect.bisect_left(ruiseki,sum(A)/2)
print(i)
print(min(abs(sum(A[:i])-sum(A[i:])),abs(sum(A[:i-1])-sum(A[i-1:]))))

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
ruiseki = [0]+list(itertools.accumulate(A))
i = bisect.bisect_left(ruiseki,sum(A)/2)
print(abs(sum(A[:i])-sum(A[i:])))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
tmp=0
for i in range(n): 
    tmp+=a[i]
    if tmp*2==sum(a):
        print(0)
        sys.exit()
    if tmp*2>sum(a):
        l=i
        continue
if abs(tmp*2-sum(a))>abs((tmp-a[l])*2-sum(a)):
    print(abs((tmp-a[l-1])*2-sum(a)))
else:
    print(abs(tmp*2-sum(a)))

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
div = sum(A)//2
nya = 0
pivot = 0
for i in range(n):
    nya += A[i]
    if nya >= div:
        pivot = i
        break
#print(i)
print(abs(sum(A[i+1:]) - nya))

Submission status: Wrong Answer

Solution code:
import sys


if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    cost = 0
    a_l = []
    a_r = []
    if n%2 == 0:  
        for i in range(n//2):
            a_l.append(a[i])
        for i in range(n//2,n):
            a_r.append(a[i])
        sum_a_l = sum(a_l)
        sum_a_r = sum(a_r)
        cost = abs(sum_a_l-sum_a_r)
    else:
        for i in range(n//2+1):
            a_l.append(a[i])
        for i in range(n//2+1,n):
            a_r.append(a[i])
        sum_a_l = sum(a_l)
        sum_a_r = sum(a_r)
        cost = abs(sum_a_l-sum_a_r)
    print(cost)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
temp=sum(a)
ans=0
t=999999999
tsum=0
ta=0
for i in range(n):
  tsum=tsum+a[i]
  if abs(tsum-temp/2)<t:
    t=abs(tsum-temp/2)
    ta=tsum
print(abs(int(ta)*2-temp))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
temp=sum(a)
ans=0
t=999999999
tsum=0
ta=0
for i in range(n):
  tsum=tsum+a[i]
  if abs(tsum-temp/2)<t:
    t=abs(tsum-temp/2)
    ta=tsum
print(int(ta)*2-temp)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
temp=sum(a)
ans=0
t=999999999
tsum=0
for i in range(n):
  tsum=tsum+a[i]
  if abs(tsum-temp/2)<t:
    t=abs(tsum-temp/2)
print(int(t)*2-temp)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sm=sum(a)
x=[a[0]]
y=[sm-a[n-1]]
for i in range(1,n):
  x.append(x[i-1]+a[i])
  y.append(sm-x[i])
min=9999999999
for (p,q) in zip(x,y):
  sa=abs(p-q)
  if sa<min:
    min=sa

print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sm=sum(a)
i=-1
x=0
while sm/2>x:
  i+=1
  if i==n-1:
    i-=1
    break
  x=sum(a[:i+1])

print(abs(2*sum(a[:i+1])-sm))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sm=sum(a)
i=0
han=0

while sm/2>sum(a[:i+1]):
  i+=1
i-=1
print(abs(2*sum(a[:i+1])-sm))