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:
import math 

length_of_segments=[]
number_of_sections=int(input())
segment_arr=input().split(" ")
for num in segment_arr:
    length_of_segments.append(int(num))
#print(length_of_segments)
mid_length=sum(length_of_segments)/2

cumulative=0
remainder=0
for e in length_of_segments:
    if (cumulative + e) > mid_length:
        remainder=mid_length-(cumulative)
        #print(e, cumulative,remainder)
        break
    else:
        cumulative += e
print(math.ceil(remainder))

Submission status: Wrong Answer

Solution code:
import numpy as np 
import math 

number_of_sections=int(input())
segment_arr=input().split(" ")
length_of_segments=[int(num) for num in segment_arr]

mid_length=np.sum(length_of_segments)/2

cumulative=0
remainder=0
for e in length_of_segments:
    if (cumulative + e) > mid_length:
        remainder=mid_length-(cumulative)
        print(e, cumulative,remainder)
        break
    else:
        cumulative += e
print(math.ceil(remainder))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

    cum_len = [0] * len(al)
    cum_len[0] = al[0]
    for i in range(1, len(al)):
        cum_len[i] = cum_len[i-1] + al[i]

    # print(sum(al))
    ans = 1000000
    for i in range(len(al)):
        left = cum_len[i]
        right = cum_len[-1] - cum_len[i]
        # print(left, right)
        ans = min(ans, abs(left - right))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

    cum_len = [0] * len(al)
    cum_len[0] = al[0]
    for i in range(1, len(al)):
        cum_len[i] = cum_len[i-1] + al[i]

    # print(sum(al))
    ans = 1000000
    for i in range(len(al)-1):
        left = cum_len[i]
        right = cum_len[-1] - cum_len[i]
        # print(left, right)
        ans = min(ans, abs(left - right))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

    cum_len = [0] * len(al)
    cum_len[0] = al[0]
    for i in range(1, len(al)):
        cum_len[i] = cum_len[i-1] + al[i]

    ans = 1000000
    for i in range(len(al)-1):
        left = cum_len[i]
        right = cum_len[-1] - cum_len[i]
        ans = min(ans, abs(left - right))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

    length = sum(al)
    half_len = length // 2

    right_cut_len = 0
    left_cut_len = 0
    current_len = 0
    for i in range(len(al)):
        paul = al[i]
        if current_len + paul > half_len:
            right_cut_len = current_len + paul
            break
        current_len += paul

    left_cut_len = current_len

    left_cost = length - left_cut_len
    right_cost = length - right_cut_len
    # print(left_cost, right_cost)
    print(min(left_cost, right_cost))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_b

import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

    length = sum(al)
    half_len = length // 2

    current_len = 0
    for i in range(len(al)):
        paul = al[i]
        if current_len + paul > half_len:
            break
        current_len += paul

    rest_len = length - current_len
    print(abs(current_len - rest_len))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

half = 0

for i in range(N):
	half += A[i]
	if half >= tot/2:
		break

print(abs(tot-half-half))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ac
from bisect import bisect_left as bl
n=int(input())
a=list(ac(list(map(int,input().split()))))
print(abs(a[-1]-2*a[bl(a,a[-1]//2)]))

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))

import numpy as np

N=int(input())
bars=acinput()

bar_cs=np.cumsum(bars)

res=10**9

for i in range(N-1):
    R=bar_cs[-1]-bar_cs[i]
    L=bar_cs[i]
    res=min(res,np.abs(R-L))
    #print(i,L,R)

print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr = list(map(int,input().split()))
k=0
if n%2==1:
	k1=0
	k2=0
	for i in range(n//2):
		k1=k1+arr[i]-arr[n-i-1]
	print(abs(abs(k1)-arr[n//2]))
else:
	for i in range(n//2):
		k=k+arr[i]-arr[n-1-i]
	print(abs(k))

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
if n%2==0:
  s1=sum(a[0:n//2])
  s2=sum(a[n//2:n])
  k=abs(s1-s2)
else:
  s1=sum(a[0:n//2+1])
  s2=sum(a[n//2+1:n])
  
  s3=sum(a[0:n//2])
  s4=sum(a[n//2:n])
  k=min(abs(s1-s2),abs(s3-s4))
print(abs(k))

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
if n%2==0:
  s1=sum(a[0:n//2])
  s2=sum(a[n//2:n])
else:
  s1=sum(a[0:n//2+1])
  s2=sum(a[n//2+1:n])
print(abs(s1-s2))

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
o=0
e=0
a = list(map(int, input().rstrip().split()))
for i in range(0,n):
  if a[i]%2==1:
    o+=a[i]
  else:
    e+=a[i]
if(o%2==0):
  print("0")
else:
  print(o)

Submission status: Wrong Answer

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

for i in range(N):
        s+=n[i]
        if s>=l/2:
                e=l-s
                break

        e+=n[N-i-1]
        if e>=l/2: 
                s=l-e
                break
print(abs(s-e))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    r = [0] * (N+1)
    rr = [0] * (N+1)

    for i in range(1,N+1):
        r[i] = r[i-1] + A[i-1]
        rr[i] = rr[i-1] + A[i-1]-1

    from bisect import bisect_left, bisect_right
    c = sum(A)/2
    p = min(abs(r[bisect_left(r, c)]-c), abs(r[bisect_right(r, c)]-c))
    print(int(p/0.5))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    r = [0] * (N+1)
    rr = [0] * (N+1)

    for i in range(1,N+1):
        r[i] = r[i-1] + A[i-1]
        rr[i] = rr[i-1] + A[i-1]-1

    from bisect import bisect_left
    c = sum(A)/2
    p = bisect_left(r, c)
    t = (r[p] - c)/0.5
    print(int(t))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x = 0
y = 0

for i in range(N):
    x = sum(A[:i])
    y = sum(A[i:])
    if ans > abs(x - y):
        ans = abs(x - y)

print(ans)

Submission status: Wrong Answer

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

if int(N[0]) >= 2 and int(N[0]) <= 200000:
  n = int(N[0])
  for i in range(n):
    if int(A[i]) >= 1 and int(A[i]) <= 2020202020:
      a.append(int(A[i]))

right = 0
left = 0
cnt = 0
herf = 0

for i in range(n):
  cnt += a[i]
herf = int(cnt/2)
for i in range(n):
  left += a[i]
  if left > herf:
    left -= a[i]
    right = cnt - left
    break
print(left-right)

Submission status: Wrong Answer

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

if n % 2 == 0:
    print(abs(sum(l[:n//2]) - sum(l[n//2:])))
else:
    idx = n//2 +1
    idx2 = n//2 -1 
    ans = min(abs(sum(l[:idx]) - sum(l[idx:])),abs(sum(l[:idx2]) - sum(l[idx2:])))
    print(ans)

Submission status: Wrong Answer

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

if n % 2 == 0:
    print(abs(sum(l[:n//2]) - sum(l[n//2:])))
else:
    idx = n//2 +1 
    ans = abs(sum(l[:idx]) - sum(l[idx:]))
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy
N = int(input())
A = list(map(int,input().split()))
tmp1 = [A[0]]
tmp2 = [sum(A)]
for i in range(1,N):
    tmp1.append(tmp1[i-1]+A[i])
    tmp2.append(tmp2[i-1]-A[i-1])
tmp1 = numpy.array(tmp1)
tmp2 = numpy.array(tmp2)
ans = list(map(abs,list(tmp1 - tmp2)))
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(n) for n in input().split()]
T = sum(A)
M = T/2
L = 0
idx = 0
while L < M:
    L += A[idx]
    idx += 1
R = sum(A[idx:])
print(abs(L-R))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int, input().split()))
A=np.array(A)
left=0 
right=N-1
while left<right:
  ans=10**15
  mid=(left+right)//2
  if A[:mid+1].sum()<A[mid+1:].sum():
    ans=min(ans,abs(A[:left+1].sum()-A[left+1:].sum()))
    left=mid+1
  else:
    right=mid
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int, input().split()))
A=np.array(A)
left=0 
right=N-1
while left<right:
  ans=10**15
  mid=(left+right)//2
  if A[:mid+1].sum()<A[mid+1:].sum():
    left=mid+1
    ans=min(ans,abs(A[:left+1].sum()-A[left+1:].sum()))
  else:
    right=mid
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int, input().split()))
A=np.array(A)
left=0 
right=N-1
while left<right:
  ans=10*15
  mid=(left+right)//2
  if A[:mid+1].sum()<A[mid+1:].sum():
    left=mid+1
    ans=min(ans,abs(A[:left+1].sum()-A[left+1:].sum()))
  else:
    right=mid
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int, input().split()))
A=np.array(A)
left=0 
right=N-1
while left<right:
  ans=0
  mid=(left+right)//2
  if A[:mid+1].sum()<A[mid+1:].sum():
    left=mid+1
    ans=min(ans,abs(A[:left+1].sum()-A[left+1:].sum()))
  else:
    right=mid
print(ans)

Submission status: Wrong Answer

Solution code:

n=int(input())
l=list(map(int,input().split()))
tot=sum(l)
f=0
ans=0
for i in range(n):
    ans+=l[i]
    f=0
    if ans*2==tot:
        f=1
        break
if f:
    print(0)
else:
    ans=0
    tr=10**9+7
    for i in range(n):
        ans+=l[i]
        #print(ans,tr)
        tr=min(tr,abs(ans-(tot-ans)))
    print(tr)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
tot=sum(l)
f=0
ans=0
for i in range(n):
    ans+=l[i]
    f=0
    if ans*2==tot:
        f=1
        break
if f:
    print(0)
else:
    ans=0
    tr=10**9+7
    for i in range(n):
        ans+=l[i]
        print(ans,tr)
        tr=min(tr,abs(ans-(tot-ans)))
    print(tr)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
tot=sum(l)
tr=100000000000
f=0
te=0
if tot%2==0:
    f=1
    te=tot//2
c=1
for i in range(n-1):
    c=1
    ans+=l[i]
    #print(tr,ans,tot)
    tr=min(tr,tot-ans)
    
    if te==ans and f:
        print(0)
        f=0
        c=0
        break
    
if c:
    print(tr)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
point = 10**9 + 10

cut_l = A[0]
cut_r = sum(A[1:])

for i in range(1, N):
    cut_l += A[i]
    cut_r -= A[i]
    if abs(cut_l - cut_r) < point:
        point = abs(cut_l - cut_r)

print(point)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
point = 10**9 + 10

for i in range(N):
    cut_l = sum(A[:i])
    cut_r = sum(A[i:])
    if 0 <= abs(cut_l - cut_r) < point:
        point = abs(cut_l - cut_r)
        if point == 0:
            break

print(point)

Submission status: Wrong Answer

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

j=0

for i in range(n):
  j+=l[i]
  if j*2==s:
    print(0)
    break
  elif j*2>s:
    print((j*2)-s)
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
cost = S%2
S = S//2 + S%2
b = 0
for a in A:
    b += a
    if b>=S:
        print(cost+min(abs(b-a-S),abs(b-S))*2)
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input().split())
s = sum(int(i) for i in l)
m0 = 0
m1 = 0
c = 0
for i in l:
    m1 = m0
    m0 += int(i)
    if m0 * 2 == s:
        break
    elif m0 * 2 > s:
        c = m0 *2 -s
        break
        
print(c)

Submission status: Wrong Answer

Solution code:
li = list(map(int, input().split()))
li_a = list(reversed(li))
from collections import deque
a = 0
b = sum(li)
while a < b//2:
  s = li.pop()
  a += s
c = sum(li)

d = 0
e = sum(li_a)
while d < e//2:
  s = li_a.pop()
  d += s
f = sum(li_a)
print(min(a-c, d-f))

Submission status: Wrong Answer

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

part_sum = 0
for i, a in enumerate(A):
    part_sum += a
    if part_sum >= all_sum // 2:
        print(part_sum - (all_sum - part_sum))
        break

Submission status: Wrong Answer

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

part_sum = 0
for i, a in enumerate(A):
    part_sum += a
    if part_sum >= -(-all_sum // 2):
        print(part_sum - (all_sum - part_sum))
        break

Submission status: Wrong Answer

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

part_sum = 0
for i, a in enumerate(A):
    part_sum += a
    if part_sum >= all_sum / 2:
        print(part_sum - (all_sum - part_sum))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 0
s = []
for i in range(len(a)):
    m += a[i]
    s.append(abs(sum(a) - m*2))
    if len(s) > 1 and s[-1] < s[-2]:
        break
print(min(s))

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
s=sum(a)
c=0
for b in a:c+=b;n=min(n,abs(c+c-s))
print(n)

Submission status: Wrong Answer

Solution code:
n =int(input())
a=list(map(int, input().split()))
m=0
s=[2020202020]
for i in range(len(a)):
    m+=a[i]
    mins=min(s)
    s.append(abs(sum(a)-m*2))
    if mins<s[i]:
        break
print(min(s))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
sm = sum(As)
p = 0
for a in As[:-1]:
  if p >=sm:
    break
  p+=a
  sm-=a
print(abs(sm-p))

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
sm = sum(As)
p = 0
for a in As:
  if p >=sm:
    break
  p+=a
  sm-=a
print(abs(sm-p))

Submission status: Wrong Answer

Solution code:
n =int(input())
a=list(map(int, input().split()))
m=0
s=[2020202021]
for i in range(len(a)):
    m+=a[i]
    mins=min(s)
    s.append(abs(sum(a)-m*2))
    if mins<s[i]:
        break
print(mins)

Submission status: Wrong Answer

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

l, r = sum(A[:n//2]), sum(A[n//2:])

if n % 2 == 0:
    print(abs(l-r))
else:
    m = A[n//2]
    s, b = min(l, r-m), max(l, r-m)
    print(abs(b-s-m))

Submission status: Wrong Answer

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

l, r = sum(A[:n//2]), sum(A[n//2:])

if n % 2 == 0:
    print(abs(l-r))
else:
    m = A[n//2]
    s, b = min(l, r-m), max(l, r-m)
    print(b-s-m)

Submission status: Wrong Answer

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

for i in range(N):
    if sum(A[:i]) >= sum(A) / 2:
        print(sum(A[:i]) - sum(A[i:]))
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]
Sum = 0
for s in input().split():
    s = int(s)
    Sum += s
    A.append(Sum)
mid = A[-1]//2
ans = 2*min(abs(A[i]-mid) for i in range(N+1))
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), dtype='int')
s = A.sum()
i = -1
left_length = 0
while left_length < s / 2:
    i += 1
    left_length += A[i]
# print(i, left_length, s)
right_length = s - left_length
print(left_length - right_length)

Submission status: Wrong Answer

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

total=0
for i in range(N):
  total = total + A[i]
  
amount=0
half=0
for i in range(N):
    amount = amount+A[i]
    if amount<=(total//2):
        half = half + 1
    else:
        break

lefttotal=0
for i in range(half):
    lefttotal = lefttotal + A[i]
    
righttotal = total - lefttotal

print( righttotal - lefttotal )

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
s = sum(a)
t = i = 0
while i < n - 1 and t * 2 < s:
	t += a[i]
	i += 1
print(min(abs(t * 2 - s), abs((t - a[i]) * 2 - s)))

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
s= sum(a)
t=i=0
while i<n-1 and t*2<s:
	t+=a[i]
	i+=1
print(max(t*2-s, s-2*t))

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
s = sum(a)
l = r = 0
t = 0
m = s
while l < n:
	while r < n and t * 2 < s:
		t += a[r]
		r += 1
	if t * 2 >= s:
		m = min(m, 2 * t - s)
	t -= a[l]
	l += 1
print(m)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
s = sum(a)
l = r = 0
t = 0
m = s
while l < n:
	while r < n and t < s // 2:
		t += a[r]
		r += 1
	if t * 2 >= s:
		m = min(m, 2 * t - s)
	t -= a[l]
	l += 1
print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = map(int,input().split())
a = list(map(int,input().split()))
a_sum = sum(a)
kyoukaisen = a_sum /2
left = 0

for i in range(len(a)):
    left += a[i]
    
    if left >= kyoukaisen:
        print(min(abs(a_sum - 2*left),abs( (a_sum - left-a[i]) - (a_sum-(a_sum - left-a[i]))) ))
        break

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
asum2=sum(a)/2
j,k=0,0
for i in range(n):
  j+=a[i]
  if j>=asum2:
    break
for i in range(n):
  k+=a[n-i-1]
  if k>=asum2:
    break
if j-asum2>k-asum2:
  print(int(2*j-2*asum2))
else:
  print(int(2*k-2*asum2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
asum2=sum(a)/2
j,k=0,0
for i in range(n):
  j+=a[i]
  if j>=asum2:
    break
for i in range(n):
  k+=a[n-i-1]
  if k>=asum2:
    break
if j-asum2>k-asum2:
  print(2*j-2*asum2)
else:
  print(2*k-2*asum2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L, df = L + 1, df + A[L]
    else:
        R, df = R - 1, df - A[R]
print(abs(df))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L, df = L + 1, df - A[L]
    else:
        R, df = R - 1, df + A[R]
print(abs(df))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

lines = sys.stdin.readlines()
N = int(lines[0])

stdin = list(map(int,lines[1].split(' ')))
lst = np.zeros((3,N), dtype=np.int32)

i = 0
for a,b in zip(stdin, stdin[::-1]):
    lst[0,i:] += a
    lst[1,i:] += b
    i += 1

lst[1, :] = lst[1, ::-1]
for i in range(N):
    lst[2, i] = abs(lst[0,i] - lst[1,i])

print(min(lst[2]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = map(int,input().split())
a = list(map(int,input().split()))
a_sum = sum(a)
kyoukaisen = a_sum /2
left = 0

for i in range(len(a)):
    left += a[i]
    
    if left >= kyoukaisen:
        print(min(abs(a_sum - 2*left),abs( (a_sum) - ((left-a[i])+a[i]) ) ))
        break

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
asum2=sum(a)//2
j,k=0,0
for i in range(n):
  j+=a[i]
  if j>=asum2:
    break
for i in range(n):
  k+=a[n-i-1]
  if k>=asum2:
    break
if j-asum2>k-asum2:
  if sum(a)%2==0:
    print(2*j-2*asum2)
  else:
    print(2*j-2*asum2+1)
else:
  if sum(a)%2==0:
    print(2*k-2*asum2)
  else:
    print(2*k-2*asum2+1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

lines = sys.stdin.readlines()
N = int(lines[0])

stdin = list(map(int,lines[1].split(' ')))
lst = np.zeros((3,N), dtype=np.int32)

i = 0
for a,b in zip(stdin, stdin[::-1]):
    lst[0,i:] += a
    lst[1,i:] += b
    lst[2, i] = abs(lst[0,i] - lst[1,i])
    i += 1

print(min(lst[2]))

Submission status: Wrong Answer

Solution code:
import sys

def expand(bou_len, cost):
    bou_len += 1
    cost += 1
    return bou_len, cost

def shrink(bou_len, cost):
    bou_len -= 1
    cost += 1
    return bou_len, cost

lines = sys.stdin.readlines()
N = int(lines[0])

lst = []
for n in map(int,lines[1].split(' ')):
    lst.append(n)

lst_sum = sum(lst)
half_len = lst_sum / 2

center_idx = 0
bar_len = 0
center_dist = 1000000
for index, element in enumerate(lst):
    bar_len += element
    if abs(half_len - bar_len) < center_dist:
        center_idx = index
        center_dist = abs(half_len - bar_len)
        if center_dist == 0:
            break

left_half = lst[:center_idx+1]
right_half = lst[center_idx+1:]

left_sum = sum(left_half)
right_sum = sum(right_half)

print(abs(left_sum - right_sum))

Submission status: Wrong Answer

Solution code:
import sys

def expand(bou_len, cost):
    bou_len += 1
    cost += 1
    return bou_len, cost

def shrink(bou_len, cost):
    bou_len -= 1
    cost += 1
    return bou_len, cost

lines = sys.stdin.readlines()
N = int(lines[0])

lst = []
for n in map(int,lines[1].split(' ')):
    lst.append(n)

lst_sum = sum(lst)
half_len = lst_sum / 2

center_idx = 0
bar_len = 0
center_dist = 1000000
for index, element in enumerate(lst):
    bar_len += element
    if abs(half_len - bar_len) < center_dist:
        center_idx = index
        center_dist = abs(half_len - bar_len)
        if center_dist == 0:
            break

left_half = lst[:center_idx+1]
right_half = lst[center_idx+1:]

left_sum = sum(left_half)
right_sum = sum(right_half)

print(left_sum - right_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa*2 == L:
    break
  elif nagasa*2 > L:
    if i == 0:
      ans = abs(L - (nagasa *2))
    else:
      ans = min(abs(L - (nagasa *2)), abs(L - (sum(a[0:i-1]) *2)))

    break
    

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0

for i in range(n):
  nagasa += a[i]
  if nagasa == L/2:
    break
  elif nagasa > L/2:
    if i == 0:
      sa = abs(nagasa - L/2)
    elif i == n-1:
      sa = abs(L/2-sum(a[0:i-1]))
    else:
      sa = min(abs(nagasa - L/2),abs(L/2-sum(a[0:i-1])))
    
    ans = int(sa * 2)
    break
    

print(ans)

Submission status: Wrong Answer

Solution code:
print("I don't understand")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0
for i in range(n):
  nagasa += a[i]
  if nagasa == L/2:
    break
  elif nagasa > L/2:
    if i == 0:
      sa = abs(nagasa - L/2)
    else:
      sa = min(abs(nagasa - L/2),abs(L/2-sum(a[0:i-1])))
    
    ans = int(sa * 2)
    break
    

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

L = sum(a)

nagasa = 0

ans = 0

i=0
for i in range(n):
  nagasa += a[i]
  if nagasa == L/2:
    break
  elif nagasa > L/2:
    sa = min(abs(nagasa - L/2),abs(L/2-sum(a[0:i-1])))
    ans = int(sa * 2)
    break
    

print(ans)

Submission status: Wrong Answer

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

import sys
from bisect import bisect_left
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = [0] + LIST()

acc = list(accumulate(A))
mid = sum(A) / 2
l = bisect_left(acc, mid) - 1
r = bisect_left(acc, mid)
l = acc[l]
r = acc[r]
print(min(mid-l, r-mid)*2)

Submission status: Wrong Answer

Solution code:
n=int(input())
alist=list(map(int,input().split()))
blist=[alist[0]]
for i in range(1,n):
	blist.append(blist[-1]+alist[i]) #累積和
alist.reverse()
clist=[alist[0]]
for i in range(1,n):
	clist.append(clist[-1]+alist[i])
clist.reverse()
dlist=[]
for i in range(1,n):
	dlist.append(abs(blist[i]-clist[i-1]))
ans=min(dlist)
print(int(ans))

# hanbun=blist[-1]/2
# shirushi=0
# l=0
# u=n-1
# while u>l+1:
	# aida=(l+u)//2
	# if blist[aida]==hanbun:
		# index=aida
		# shirushi=1
		# break
	# elif blist[aida]>hanbun:
		# l=aida
	# elif blist[aida]<hanbun:
		# u=aida

# if shirushi==1 and blist[-1]%2==0:
	# print(0)
# else:
	# if shirushi==0:
		# if blist[u]-hanbun>hanbun-blist[l]:
			# index=l
		# else:
			# index=u

	# ans=int(2*blist[index]-blist[-1])
	# if ans<0:
		# ans=int(ans*(-1))
	# print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
alist=list(map(int,input().split()))
blist=[alist[0]]
for i in range(1,n):
	blist.append(blist[-1]+alist[i]) #累積和
alist.reverse()
clist=[alist[0]]
for i in range(1,n):
	clist.append(clist[-1]+alist[i])
clist.reverse()
dlist=[]
for i in range(n):
	dlist.append(abs(blist[i]-clist[i]))
ans=min(dlist)
print(int(ans))

# hanbun=blist[-1]/2
# shirushi=0
# l=0
# u=n-1
# while u>l+1:
	# aida=(l+u)//2
	# if blist[aida]==hanbun:
		# index=aida
		# shirushi=1
		# break
	# elif blist[aida]>hanbun:
		# l=aida
	# elif blist[aida]<hanbun:
		# u=aida

# if shirushi==1 and blist[-1]%2==0:
	# print(0)
# else:
	# if shirushi==0:
		# if blist[u]-hanbun>hanbun-blist[l]:
			# index=l
		# else:
			# index=u

	# ans=int(2*blist[index]-blist[-1])
	# if ans<0:
		# ans=int(ans*(-1))
	# print(ans)

Submission status: Wrong Answer

Solution code:
num=input()
num=eval(num)
nums=input()
nums=nums.split()
for i in range(len(nums)):
  nums[i]=eval(nums[i])
count=sum(nums)+1
half=count//2
temp=0
mloss=999999
for i in range(len(nums)):
  if abs(temp+nums[i]-half)<=mloss:
        temp+=nums[i]
        mloss=abs(temp-half)
  else:
      break
print((count-2*min(temp,count-temp))//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int, input().split()))
tmp = 0
ind = 0
for i in range(n):
    tmp += la[i]
    if 2*tmp >= sum(la):
        ind = i
        break
if n == 2:
    ans = abs(la[0]-la[1])
else:
    ans = abs(tmp - (sum(la)-tmp))
print(ans)