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:
n = int(input())
r = 0
l = 0
a = list(map(int,input().split()))
for i in range(n//2):
    r += a[i]
    l += a[n-1-i]
if n%2==1:
    if r<l:r+=a[n//2]
    else:l+=a[n//2]
print(abs(r-l))

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]
ans = n
for x in a[:n-1]:
    ans = min(ans, abs(a[n-1] - 2 * x))
print(ans)

Submission status: Wrong Answer

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

result = 2020202020

for i in range(1, n-1):
    result = min(result, abs(sum(a[:i+1]) - sum(a[i+1:])))
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(map(int, input().split()))
s = sum(al)
acc = 0
res = 10**9
for a in al:
    acc += a
    res = min(res, abs((s-acc)-acc))
print(res)

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,A:list) -> int:
   ans = 10**9
   for i in range(1,N):
      tmp = abs(sum(A[:i]) -sum( A[i:]))
      ans = min(tmp,ans)
   return ans
   

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

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,A:list) -> int:

   if(N % 2 == 1):
      left = sum(A[:N//2])
      right = sum(A[N//2+1:])
      middle = A[N%2]
   else:
      left = sum(A[:N//2])
      right = sum(A[N//2:])
      middle = 0
   # print(left,right,middle)
   if(left > right):
      return abs(right - left + middle)
   else:
      return abs(left - right+middle)
   

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

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,A:list) -> int:
   total = 0
   N = len(A)
   if(N % 2 == 0):
      N //= 2
      total = max(sum(A[:N]),sum(A[N:])) - min(sum(A[:N]),sum(A[N:]))
      return total
      
   else:
      N //= 2
      left = sum(A[:N])
      right = sum(A[N+1:])
      if(left == right):
         return A[N]
      elif(left < right):
         return right
      else:
         return left


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

Submission status: Wrong Answer

Solution code:

def myAnswer(N:int,A:list) -> int:
   total = 0
   length = len(A)
   if(length % 2 == 0):
      length //= 2
      total = max(sum(A[:length]),sum(A[length:])) - min(sum(A[:length]),sum(A[length:]))
      return total
      
   else:
      length //= 2
      print(A[:length],A[length+1:],A[length])
      left = sum(A[:length])
      right = sum(A[length+1:])
      if(left == right):
         return A[length]
      elif(left < right):
         return right
      else:
         return left


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

Submission status: Wrong Answer

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

def ruiseki(a):
    right, left = [], []
    l, r = 0, 0
    for i in range(n):
        l += a[i]
        left.append(l)
    
        r += a[-(i+1)]
        right.append(r)
    return left, right[::-1]

cnt = 0
flag = True
while flag:
    l, r = ruiseki(a)

    min_ind = 0
    mins = 1000000000000
    for i in range(n-1):
        if l[i] == r[i+1]:
            flag = False
            break
        
        if mins > abs(l[i] - r[i]):
            min_ind = i
            mins = abs(l[i] - r[i])
    if flag:
        cnt+=1
        a[min_ind] -= 1
        print(a)
print(cnt)

Submission status: Wrong Answer

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

if n % 2 == 0:
  print(abs(sum(x[:n//2]) - sum(x[n//2:])))

else:
  center = n // 2
  left = sum(x[:center])
  right = sum(x[center+1:])
  print(x[center] - abs(left - right))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
c = total / 2
dist = total
tmp = 0
p = 0
for i, bar in enumerate(a):
    tmp += bar
    if dist > abs(c - tmp):
        p = i
    if tmp >= c:
        break
l = sum(a[:p + 1])
r = sum(a[p + 1:])
ans = abs(l - r)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()] 

su = [0 for _ in range(n)] #鉄の棒の切れ目の座標
for i in range(n):
    su[i] = su[i-1] + a[i]
#print(su)

tmp = 2 * pow(10, 5) + 1
for i in su:
    if abs(i - su[-1]/2) < tmp:
        tmp = abs(i - su[-1]/2)
#print(su[-1]/2, tmp)

"""
#中心に一番近い鉄の棒の切れ目と中心との距離の差
l = 0
r = n-1
while (l - r) >= 1:
    c = (l + r) // 2
    #print(l, r, c)
    if su[c] < su[-1] / 2:
        l = c
    elif su[c] > su[-1] / 2:
        r = c
#print(su[l], su[r])
tmp = min(abs(su[l] - su[-1]/2), abs(su[r] - su[-1]/2))
print(tmp)
"""

ans = 2 * tmp
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()] 

su = [0 for _ in range(n)] #鉄の棒の切れ目の座標
for i in range(n):
    su[i] = su[i-1] + a[i]
#print(su)

tmp = 2 * pow(10, 5) + 1
for i in su:
    if abs(i - su[-1]/2) < tmp:
        tmp = abs(i - su[-1]/2)
#print(su[-1]/2, tmp)

"""
#中心に一番近い鉄の棒の切れ目と中心との距離の差
l = 0
r = n-1
while (l - r) >= 1:
    c = (l + r) // 2
    #print(l, r, c)
    if su[c] < su[-1] / 2:
        l = c
    elif su[c] > su[-1] / 2:
        r = c
#print(su[l], su[r])
tmp = min(abs(su[l] - su[-1]/2), abs(su[r] - su[-1]/2))
print(tmp)
"""

ans = 2 * tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
s = sum(li)
sum_li = []
for i,l in enumerate(li):
    if i == 0:
        sum_li.append(l)
        continue
    sum_li.append(sum_li[-1]+l)
all_li = []
for ss in sum_li:
    #print(s,ss)
    all_li.append(abs(s-ss))
print(min(all_li))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    minans = 10 ** 9
    for i in range(N - 1):
        val=abs(sum(A[:i + 1]) - sum(A[i + 1:]))
        minans=min(minans,val)
    print(minans)


resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    minans = 10 ** 9
    for i in range(N - 1):
        if abs(sum(A[:i + 1]) - sum(A[i + 1:])) < minans:
            minans = abs(sum(A[:i + 1]) - sum(A[i + 1:]))
    print(minans)


resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
countUp = 0
sumA = sum(A)
minA = 10 ** 9 + 7
for x in range(N):
    countUp += A[x]
    sumA -= A[x]
    minA = min(minA, abs(countUp - sumA))
print(minA)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
minA = 10 ** 9 + 7
for x in range(N):
    slice_sumA = sum(A[:x])
    remainA = sumA - slice_sumA
    minA = min(minA, abs(slice_sumA - remainA))
print(minA)

Submission status: Wrong Answer

Solution code:
import itertools


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

reg=10**9
for i in range(N):
    reg = min(reg,
             abs(Acum[-1] - Acum[i] * 2))
    
print(reg)

Submission status: Wrong Answer

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

reg=10**9

for i in range(N):
    tmp = abs(sum(A[:i]) - sum(A[i:]))
    reg = min(reg, tmp)
print(reg)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = float("INF")
LS = [0]*(N+1)
LS[0] = 0
for i in range(N-1):
  LS[i+1] = A[i] + LS[i]
  ans = min(ans, abs(S - LS[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 10**9
total = sum(A)
acc = 0
for a in A:
  acc += a
  ans = min(ans, abs(total - acc * 2))
print(ans)

Submission status: Wrong Answer

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

lst = []
for i in range(0, N-1):
    a = abs(sum(A[:i]) - sum(A[i:]))
    lst.append(a)
#print(lst)
print(min(lst))

Submission status: Wrong Answer

Solution code:
from numpy import cumsum

N = int(input())
A = list(map(int, input().split()))
a_cum = cumsum(A)
inv_a_cum = [a_cum[-1] - a_cum[i] for i in range(N)]

ans = 10**9
for i in range(N):
    ans = min(ans, abs(a_cum[i] - inv_a_cum[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from numpy import cumsum

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

ind = bisect_left(a_cum, a_cum[-1]/2)
print(abs((a_cum[-1] - a_cum[ind]) - a_cum[ind]))

Submission status: Wrong Answer

Solution code:
import sys
def input() : return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    left_sum = [0] * N # [0, i]
    right_sum = [0] * N # [i, N-1]

    left_sum[0] = A[0]
    right_sum[-1] = A[-1]

    for i in range(1, N):
        left_sum[i] = left_sum[i-1] + A[i]
        right_sum[(N-1)-i] = right_sum[(N-1)-(i-1)] + A[(N-1)-i]
    
    ans = 10 ** 9
    for i in range(N-1):
        diff = abs(left_sum[i] - right_sum[i+1])
        ans = min(ans, diff)
    
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
num = int(input())
num_list = list(map(int,input().split()))
ans = sum(num_list)//2
#numl = sum(num_list[:num//2])
#numr = sum(num_list[num//2:num])
#print(ans,numl,numr)
total = 0
flag = "off"
for i in range(num):
  total += num_list[i]
  if total >= ans:
    n1 = total - num_list[i]
    n2 = total
    break
#print(n1,n2)
print(min((n2-ans),(ans-n1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect
n = int(input())
A = list(map(int,input().split()))
cs = np.cumsum(A).tolist()
mid = sum(A)//2
idx = bisect.bisect_left(cs, mid)
ans = float('inf')
for i in range(max(1, idx-1), min(idx+2, n)):
    x = A[:i]
    y = A[i:]
    print(x,y)
    sum_x = sum(x)
    sum_y = sum(y)
    ans = min(ans, abs(sum_x - sum_y))
print(ans)

Submission status: Wrong Answer

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

cs = np.cumsum(A).tolist()
mid = sum(A)//2
idx = bisect.bisect_left(cs, mid)

ans = float('inf')
for i in range(max(0, idx-1), idx+1):
    x = A[:i]
    y = A[i:]
    sum_x = sum(x)
    sum_y = sum(y)
    ans = min(ans, abs(sum_x - sum_y))
print(ans)

Submission status: Wrong Answer

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

ca = [0]
for i in range(n):
    ca.append(A[i]+ca[i])

print(ca)
ans = 2020202020
for i in range(n):
    ans = min(ans, abs(ca[i]-(ca[-1]-ca[i])))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
su=0
mi=2000000
for i in range(n):
  su+=a[i]
  
c=0  
for i in range(n):
  c+=a[i]
  left=su-c
  mi=min(mi,max((c-left),(left-c)))

print(mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
su=0
mi=2000000
for i in range(n):
  su+=a[i]
  left=n-su
  mi=min(mi,max((su-left),(left-su)))

print(mi)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
cnt_1 = 0
cnt_2 = 0
cnt_3 = 0
cnt_4 = 0
for i in range(n):
    if math.ceil(n / 2) > i:
        cnt_1 += a[i]
    else:
        cnt_2 += a[i]
    if math.floor(n / 2) > i:
        cnt_3 += a[i]
    else:
        cnt_4 += a[i]

print(min(abs(cnt_1 - cnt_2), abs(cnt_3 - cnt_4)))

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
cnt_1 = 0
cnt_2 = 0
for i in range(n):
    if math.ceil(n / 2) > i:
        cnt_1 += a[i]
    else:
        cnt_2 += a[i]

print(abs(cnt_1 - cnt_2))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate


def main():
    section_num = int(input())
    length = list(map(int, input().split()))
    accumulate_length = list(accumulate(length))
    answer = float("inf")
    for i in range(1, section_num):
        answer = min(answer, abs(accumulate_length[-1] - 2 * accumulate_length[i]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    section_num = int(input())
    length = list(map(int, input().split()))
    sums = [sum(length[:section_num // 2]), sum(length[section_num // 2:])]
    answer = abs(sums[0] - sums[1])
    sums[0] += length[section_num // 2]
    sums[1] -= length[section_num // 2]
    answer = min(answer, abs(sums[0] - sums[1]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import math
import bisect
import numpy as np
mod = 10**9 + 7

# http://cav-inet.hateblo.jp/entry/2017/02/18/165141
def binary_search(list,target): 

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = (left + right)//2
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return False
	else:
		return True

n = int(input())
a = list(map(int,input().split()))
c = np.cumsum(a)
s = c[n-1]

if binary_search(c, c[n-1]/2):
    print(0)
    exit()

i = bisect.bisect_right(c, c[n-1]/2)
ans = min(2*c[i]-s, s - c[i-1]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
# Problem B - Iron Bar cutting

# input process
N = int(input())
a_list = list(map(int, input().split()))

# initialization
min_cost = 10*18
left_sum = 0
right_sum = sum(a_list)

# count process cumulative sum
for i in range(N-1):
    left_sum += a_list[i]
    right_sum -= a_list[i]
    distance = abs(left_sum - right_sum)
    min_cost = min(min_cost, distance)

# output process
print(min_cost)

Submission status: Wrong Answer

Solution code:
# Problem B - Iron Bar cutting

# input process
N = int(input())
a_list = list(map(int, input().split()))

# initialization
min_cost = 10*18

# count process
for i in range(N-1):
    left = a_list[:i+1]
    right = a_list[i+1:]
    left_sum = sum(left)
    right_sum = sum(right)
    distance = abs(left_sum - right_sum)
    min_cost = min(min_cost, distance)

# output process
print(min_cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# サンプル1はべつに3*2=6じゃなくても4*2=8（[1 3 4][2 2 4]）や5*1=10（[1 4 5]）も同じコストで実現できることがわかる
# つまり総和に近い偶数を目指す
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
print("s = {}".format(s))
tmp = arr[0]
ans = 10**10
e = -1
for i in range(1, n):
    # 超えないギリギリ
    if tmp + arr[i] <= s // 2:
        tmp += arr[i]
        e = i
    else:
        break
c = abs(s // 2 - tmp) + abs(s // 2 - sum(arr[i:]))
# print("超えない左側の合計と右側の合計 : {}, {}".format(tmp, sum(arr[i:])))
ans = min(ans, c)

e = -1
tmp = arr[0]
for i in range(1, n):
    # 超えたギリギリ
    if tmp > s // 2:
        break
    else:
        tmp += arr[i]
        e = i
c = abs(s // 2 - tmp) + abs(s // 2 - sum(arr[i:]))
# print("超えたギリギリの左側の合計と右側の合計 : {}, {}".format(tmp, sum(arr[i:])))
ans = min(ans, c)
print(ans)

Submission status: Wrong Answer

Solution code:
# サンプル1はべつに3*2=6じゃなくても4*2=8（[1 3 4][2 2 4]）や5*1=10（[1 4 5]）も同じコストで実現できることがわかる
# つまり総和に近い偶数を目指す
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
tmp = arr[0]
ans = 10**10
e = -1
for i in range(1, n):
    # 超えないギリギリ
    if tmp + arr[i] <= s // 2:
        tmp += arr[i]
        e = i
    else:
        break
c = abs(s // 2 - tmp) + abs(s // 2 - sum(arr[i:]))
ans = min(ans, c)

e = -1
for i in range(1, n):
    # 超えたギリギリ
    if tmp > s // 2:
        break
    else:
        tmp += arr[i]
        e = i
c = abs(s // 2 - tmp) + abs(s // 2 - sum(arr[i:]))
ans = min(ans, c)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
def main():
    n = int(input())
    a = [int(t)for t in input().split()]
    a_rev = a[::-1]

    cusum = [a[0]]
    rcusum = [a_rev[0]]

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

    result = []

    for i in range(n):
        result.append(abs(cusum[i]-rcusum[i]))

    print(min(result))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = list(map(int, input().split()))
t = sum(dat)
c = 0
for i in range(n):
    c += dat[i]
    if c >= (t//2):
        break
c2 = t - c
target = t//2
print(abs((c - target) + abs(c2 - target)))

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = list(map(int, input().split()))
t = sum(dat)
c = 0
for i in range(n):
    c += dat[i]
    if c >= (t//2):
        break
print(abs((t-c) - c))

Submission status: Wrong Answer

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

half = 0

i = 0
while half < sum(A) // 2:
    half += A[i]
    i += 1

# ひたすら伸ばすかひたすら縮めるかで回数の少ないほう


def minus():
    h = half
    s = sum(A)
    cnt = 0

    while h > s / 2:
        h -= 1
        s -= 1
        cnt += 1

    return cnt


def plus():
    h = half - A[i]
    s = sum(A)
    cnt = 0

    while h < s / 2:
        h += 1
        s += 1
        cnt += 1

    return cnt


ans = min(minus(), plus())

print(ans)

Submission status: Wrong Answer

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

len_f = sum(a)
sum_a = 0
min = 2020202021

for i in range(1,len(a)):
    sum_a += a[i]
    len_f -= a[i]
    if min > abs(sum_a - len_f):
        min = abs(sum_a - len_f)

print(min)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int, input().split()))
suma=sum(a)
ans=0
mindiff=10000000

for i in range(len(a)):
  ans+=a[i]
  diff=abs(2*ans-suma)
  mindiff=min(diff,mindiff)
    
print(mindiff)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int, input().split()))
suma=sum(a)
ans=0
mindiff=10000000

for i in range(len(a)):
  ans+=a[i]
  if ans>=suma/2:
    diff=abs(2*ans-suma)
    mindiff=min(diff,mindiff)
    
print(mindiff)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int, input().split()))
suma=sum(a)
ans=0
mindiff=10000000
for i in range(len(a)):
  ans+=a[i]
  if ans>=suma/2:
    diff=2*ans-suma
    mindiff=min(diff,mindiff)
    
print(mindiff)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int, input().split()))
suma=sum(a)
ans=0
diff=10000000
for i in range(len(a)):
  ans+=a[i]
  if ans>=suma/2:
    diff=2*sum(a[:i])-suma
print(diff)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int, input().split()))
suma=sum(a)
ans=0
for i in range(len(a)):
  ans+=a[i]
  if ans>=suma/2:
    chuou=i
    break
print(2*sum(a[:chuou+1])-suma)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
for i in range(n):
    while tmp > abs(s-sum(a[:i+1])*2):
        tmp = abs(s-sum(a[:i+1])*2)
        print(tmp)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
postCenter=dif=0
tmp = sys.maxsize
for i in range(n):
    if tmp < abs(sum(a[:i])-sum(a[i:])):
        tmp = abs(sum(a[:i])-sum(a[i:]))
print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
P = 10**8
X = 0
for i in range(N):
  X = X + A[i]
  P = min(P,abs(S-X*2))
print(P)

Submission status: Wrong Answer

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

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

    all_ = sum(a)
    half = all_ // 2

    t = 0
    for i in range(N):
        t += a[i]
        if t >= half:
            break
    print(abs(all_ - t - t))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
d = 10000
for i in range(n):
  s1 = sum(l[0:i])
  s2 = sum(l)-s1
  b = abs(s2-s1)
  d = min(d,b)
print(d)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
cnt = 1 # P[0] is counted forcely
min_num = P[0]
for p in P:
  if p < min_num:
    min_num = p
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
cnt = 0
min_num = P[0]
for p in P:
  if p < min_num:
    min_num = p
    cnt += 1
print(cnt)

Submission status: Wrong Answer

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

l=0
r=0

li=0
ri=0

for i in range(N):
    if l<=r:
        l+=A[li]
        li+=1
    else:
        r+=A[-1-ri]
        ri+=1
        
print(l-r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n-1):
    v = i
    if (2*s[i] >= s[n]):
        break

print(abs(2*s[v] - s[n]))

Submission status: Wrong Answer

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

for i in range(n):
    if (2*s[i] >= s[n]):
        v = i
        break
    if (i == n-1):
        v = i
        break

print(abs(2*s[v] - s[n]))

Submission status: Wrong Answer

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

for i in range(n+1):
    if (2*s[i] >= s[n]):
        v = i
        break

print(abs(s[n] - 2*s[v]))

Submission status: Wrong Answer

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

for i in range(n):
    if (2*s[i] >= s[n]):
        v = i
        break

print(abs(s[n] - 2*s[v]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
A = np.array(list(map(int, input().split())))

Acum = A.cumsum()
Bcum = A[::-1].cumsum()

print(min(abs(Acum-Bcum)))

Submission status: Wrong Answer

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

total = sum(A)

s = 0
for a in A:
	s += a
	if 2 * s >= total:
		break

print(2*s-total)

Submission status: Wrong Answer

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

x = [0]

for i in a:
	x.append(i+x[-1])

ans = 2020202021
for i in x[:-1]:
	ans = min(ans, abs(x[-1]//2 - i))

if sum(a) % 2 == 1:
	print(ans+1)
else:
	print(ans)

Submission status: Wrong Answer

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

i = 0
s = 0
while True:
	s += a[i]
	i += 1
	if s >= sum(a) // 2:
		break

print(s-(sum(a)-s))

Submission status: Wrong Answer

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

cnt = 0
for i in a:
    cnt += i
    if cnt >= s // 2:
        break

print(abs(s - 2 * cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
Asum = sum(A)
Asum2 = 0
for mid in range(len(A)):
    if 2*Asum2 > Asum:
        mid -= 1
        Asum2 -= A[mid]
        break
    Asum2 += A[mid]
Asum3 = Asum2 + A[mid]

if abs(Asum - 2*Asum2) <= abs(Asum - 2*Asum3):
    Asuma = Asum2
else:
    Asuma = Asum3
c = abs(Asum - 2*Asuma)
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
Asum = sum(A)
Asum2 = 0
for mid in range(len(A)):
    if Asum2 > Asum/2:
        mid -= 1
        Asum2 -= A[mid]
        break
    Asum2 += A[mid]
Asum3 = Asum2 + A[mid]

if abs(Asum - 2*Asum2) <= abs(Asum - 2*Asum3):
    Asuma = Asum2
else:
    Asuma = Asum3
c = abs(Asum - 2*Asuma)
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
Asum = sum(A)
Asum2 = 0
for mid in range(len(A)):
    if Asum2 > Asum/2:
        mid -= 1
        Asum2 -= A[mid]
        break
    Asum2 += A[mid]
Asum3 = Asum2 + A[mid]
c = 0
if Asum - Asum2 <= Asum3:
        Asuma = Asum2
else:
    Asuma = Asum3
c = abs(Asum - 2*Asuma)
print(c)

Submission status: Wrong Answer

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

left = 0
right = sum(A)
ans = 0
for a in A:
    left += a
    right -= a
    ans = min(ans, abs(left - right))

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    A_sum = sum(A)
    A_cumsum_l = [0 for _ in range(N)]
    A_cumsum_l[0] = A[0]
    for i in range(1,N):
        A_cumsum_l[i] = A_cumsum_l[i-1] + A[i]
    A_cumsum_r = [0 for _ in range(N)]
    for i in range(N):
        A_cumsum_r[i] = A_sum - A_cumsum_l[i]
    
    index = 0
    sub = 10**12
    for i in range(N):
        if abs(A_cumsum_l[i]-A_cumsum_r[i])<sub:
            index = i
            sub = abs(A_cumsum_l[i]-A_cumsum_r[i])

    ans = 0
    if sub%2==1:
        ans +=1
        sub +=1
    ans += sub//2

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import math
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    A_sum = sum(A)
    if A_sum%2==1:
        A_sum += 1
    
    A_cumsum = [0 for _ in range(N)]
    A_cumsum[0] = A[0]
    for i in range(1,N):
        A_cumsum[i] = A_cumsum[i-1] + A[i]
    
    index_right = bisect.bisect_left(A_cumsum,A_sum//2)
    index_left  = index_right-1
    # can 1
    can_1 = A_cumsum[-1] - A_cumsum[index_left] - A_cumsum[index_left]
    # can 2
    can_sub = A_cumsum[index_right] - (A_cumsum[-1] - A_cumsum[index_right])

    if can_sub%2 == 0:
        can_2 = can_sub//2
    else:
        can_2 = math.ceil(can_sub/2)+1
    print(min(can_1,can_2))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(N):
    C1, C2 = 0,0
    C1 = sum(A[:i+1])
    C2 = sum(A[i:])
    d = abs(C1-C2)
    D.append(d)
    
print(min(D))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = 202020
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = 202020
for i in range(n+1):
    if abs(sum_l[i]-sum_r[n-i]) < cost:
        cost = abs(sum_l[i]-sum_r[n-i])
print(cost)