Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = open(0).read().split()
x = s[0][0]
s[0] = s[0][1:]
 
while True:
  p = ord(x)-97
  if len(s[p] == 0):
    print(x.upper())
    break
  x = s[p][0]
  s[p] = s[p][1:]

Fixed submission:
s = open(0).read().split()
x = s[0][0]
s[0] = s[0][1:]
 
while True:
  p = ord(x)-97
  if len(s[p]) == 0:
    print(x.upper())
    break
  x = s[p][0]
  s[p] = s[p][1:]

Buggy python submission (verdict: Runtime Error):
s = open(0).read().split()
x = s[0][0]
s[0] = s[0][1:]
 
while True:
  p = ord(x)-97
  if len(s[p] == 0):
    print(ord(x).upper())
    break
  x = s[p][0]
  s[p] = s[p][1:]

Fixed submission:
s = open(0).read().split()
x = s[0][0]
s[0] = s[0][1:]
 
while True:
  p = ord(x)-97
  if len(s[p]) == 0:
    print(x.upper())
    break
  x = s[p][0]
  s[p] = s[p][1:]

Buggy python submission (verdict: Runtime Error):
s = open(0).read().split()
x = s[0][0]
s[0] = s[0][1:]

while True:
  p = ord(x)-97
  if len(s[p] == 0):
    print ord(x).upper()
    break
  x = s[p][0]
  s[p] = s[p][1:]


Fixed submission:
s = open(0).read().split()
x = s[0][0]
s[0] = s[0][1:]
 
while True:
  p = ord(x)-97
  if len(s[p]) == 0:
    print(x.upper())
    break
  x = s[p][0]
  s[p] = s[p][1:]
Buggy python submission (verdict: Runtime Error):
N = int(input())

res = 1
for i in range(n):
  res *= (i+1)

print(res)

Fixed submission:
n = int(input())

print(int(0.5 * n * (n+1)))

Buggy python submission (verdict: Runtime Error):
def kaijo(n):
  res = 1
  for i in range(n):
    res *= i+1
  return res

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

print(kaijo(N))

Fixed submission:
n = int(input())

print(int(0.5 * n * (n+1)))
Buggy python submission (verdict: Runtime Error):
s = input()

ans = ''
for i in s:
    if i == 'B':
        ans = ans[:-1]
    else
        ans += i
print(ans)

Fixed submission:
s = input()

ans = ''
for i in s:
    if i == 'B':
        ans = ans[:-1]
    else:
        ans += i
print(ans)

Buggy python submission (verdict: Runtime Error):
s = str(input()).split('')

text = ''

for i in s:
  if i == 'B' and len(text) > 0:
    text = text[:-1]
  else:
    text += i
    
print(text)

Fixed submission:
s = input()

ans = ''
for i in s:
    if i == 'B':
        ans = ans[:-1]
    else:
        ans += i
print(ans)
Buggy python submission (verdict: Runtime Error):
a = 1
a*= a for a in input().split()

Fixed submission:
x = 1
for a in input().split():
  x *= int(a)
if x == 175:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
input()
a = map(int, input().split())
b = 1
for i in a:
    b*=i

if b>1e18:
    b=-1;
print(b)


Fixed submission:
input()
a = list(map(int, input().split()))
a.sort()
b = 1
for i in a:
    b*=i
    if b>1e18:
        print(-1)
        exit()

# if b>1e18:
#     b=-1;
print(b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
if n%a<=a:
    print("Yes")
else:
    print("No")


Fixed submission:
n=int(input())
a=int(input())
if n%500<=a:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
x,y=input().split()
print('<' if x<y else if x==y '=' else '>')

Fixed submission:
x,y=input().split()
print('<' if x<y else ('=' if x==y else '>'))
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if(a[0]==b[2] and a[1]==b[1] and a[2]=b[0]):
    print("YES")
else:
    print("NO")


Fixed submission:
a=input()
b=input()
if(a[0]==b[2] and a[1]==b[1] and a[2]==b[0]):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
H = int(input())
A = int(input())
 
if H%A == 0:
    ans = int(H/A)
    print(ans)
else:
    ans = int(H/A) + 1
    print(ans)

Fixed submission:
H, A = map(int, input().split())
if H%A == 0:
    ans = int(H/A)
    print(ans)
else:
    ans = int(H/A) + 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
H = input()
A = input()

if H%A == 0:
  print(H/A)
else:
  print(H/A + 1)

Fixed submission:
H, A = map(int, input().split())
if H%A == 0:
    ans = int(H/A)
    print(ans)
else:
    ans = int(H/A) + 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
H = input()
A = input()

if H%A == 0:
  return H/A
else:
  return H/A + 1

Fixed submission:
H, A = map(int, input().split())
if H%A == 0:
    ans = int(H/A)
    print(ans)
else:
    ans = int(H/A) + 1
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()

n, m = map(int, input().split(" "))

graph = {}
for node in range(1, n+1):
    graph[node] = []

for i in range(m):
    a, b = map(int, input().split(" "))
    graph[a].append(b)
    graph[b].append(a)

uses = [False] * (n+1)

def check(node):
    uses[node] = True
    kids = graph[node]
    for kid in kids:
        if not uses[kid]:
            check(kid)

next_graph_i = 1
for node in range(1, n+1):
    graph_i = next_graph_i
    if uses[node]:
        continue
    check(node)
    next_graph_i = graph_i + 1

out = graph_i - 1
print(out)

Fixed submission:
import sys
sys.setrecursionlimit(100002)

input = lambda : sys.stdin.readline().rstrip()


def main(a_s, b_s, n, m):
    graph = {}
    for node in range(1, n+1):
        graph[node] = []

    for i in range(m):
        a, b = a_s[i], b_s[i]
        graph[a].append(b)
        graph[b].append(a)

    uses = [False] * (n+1)

    def check(node):
        uses[node] = True
        kids = graph[node]
        for kid in kids:
            if not uses[kid]:
                check(kid)

    next_graph_i = 1
    for node in range(1, n+1):
        if uses[node]:
            continue
        graph_i = next_graph_i
        check(node)
        next_graph_i = graph_i + 1

    out = graph_i - 1
    print(out)

if True:
    n, m = map(int, input().split(" "))
    a_s = []
    b_s = []
    for i in range(m):
        a, b = map(int, input().split(" "))
        a_s.append(a)
        b_s.append(b)
else:
    import random
    n = random.randint(2, 100000)
    m = random.randint(1, 100000)
    
    a_s = []
    b_s = []
    for i in range(m):    
        a = random.randint(1, n-1)
        b = random.randint(a+1, n)
        a_s.append(a)
        b_s.append(b)

main(a_s, b_s, n, m)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip()

h, w, m = map(int, input().split(" "))

xs = []
ys = []
for i in range(m):
    x, y = map(int, input().split(" "))
    xs.append(x)
    ys.append(y)

xcounter = Counter(xs)
ycounter = Counter(ys)

x_most, x_most_num = xcounter.most_common(1)[0]
y_most, y_most_num = ycounter.most_common(1)[0]

out = 0
if x_most_num < y_most_num:
    #swap
    x_most_num = y_most_num
    tmp = ys
    ys = xs
    xs = tmp


out = x_most_num

y2s = [] 
for i in range(m):
    if xs[i] == x_most:
        continue
    else:  
        y2s.append(ys[i])
    

y2counter = Counter(y2s)
y2_most, y2_most_num = y2counter.most_common(1)[0]
out += y2_most_num

print(out)

Fixed submission:
import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip()

h, w, m = map(int, input().split(" "))

xs = []
ys = []
for i in range(m):
    x, y = map(int, input().split(" "))
    xs.append(x)
    ys.append(y)

xcounter = Counter(xs)
ycounter = Counter(ys)

x_most, x_most_num = xcounter.most_common(1)[0]
#y_most, y_most_num = ycounter.most_common(1)[0]

#if x_most_num < y_most_num:
#    x_most_num = y_most_num
#    tmp = ys
#    ys = xs
#    xs = tmp
#
out1 = x_most_num

if x_most_num < m:
    y2s = [] 
    for i in range(m):
        if xs[i] == x_most:
            continue
        else:  
            y2s.append(ys[i])
        
    y2counter = Counter(y2s)
    y2_most, y2_most_num = y2counter.most_common(1)[0]
    out1 += y2_most_num


y_most, y_most_num = ycounter.most_common(1)[0]

out2 = y_most_num

if y_most_num < m:
    x2s = [] 
    for i in range(m):
        if ys[i] == y_most:
            continue
        else:  
            x2s.append(xs[i])
        
    x2counter = Counter(x2s)
    x2_most, x2_most_num = x2counter.most_common(1)[0]
    out2 += x2_most_num

out = max(out1, out2)

print(out)
Buggy python submission (verdict: Runtime Error):
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())

def answer(n):
    m = int(ceil(log(n*(r-1) + r, r))) - 1

    cur = r ** (m-1)
    out = ""
    for i in range(m):
        i = n // cur
        out = out + ab[i-1]
        n -= i * cur
        cur //= r
    return out

out = answer(n)
print(out)

Fixed submission:
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())

def answer(n):
    m = int(ceil(log(n*(r-1) + r, r))) - 1

    #cur = r ** (m-1)
    out = ""

    sub = (r ** m - r) // (r-1)
    n = n - sub - 1
    for i in range(m):
        i = n % r
        out = ab[i] + out
        n //= r
        #i = n // cur
        #out = out + ab[i-1]
        #n -= i * cur
        #cur //= r
    return out

#for n in range(1, 676 + 26 + 2):
if True:
    out = answer(n)
    #print(n, out)
    print(out)

Buggy python submission (verdict: Runtime Error):
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())
m = int(ceil(log(n*(r-1) + r, r) - 1))

uhen = r ** m
sahen = n * (r-1) + r
if sahen < uhen:
    m -= 1
else:
    uhen *= r
    if sahen > uhen:
        m += 1
    else:
        pass

cur = r ** (m-1)
out = ""
for i in range(m):
    i = n // cur
    out = out + ab[i-1]
    n -= i * cur
    cur //= r


print(out)

Fixed submission:
from math import log, ceil
r = 26
ab = "abcdefghijklmnopqrstuvwxyz"
input = raw_input
n = int(input())

def answer(n):
    m = int(ceil(log(n*(r-1) + r, r))) - 1

    #cur = r ** (m-1)
    out = ""

    sub = (r ** m - r) // (r-1)
    n = n - sub - 1
    for i in range(m):
        i = n % r
        out = ab[i] + out
        n //= r
        #i = n // cur
        #out = out + ab[i-1]
        #n -= i * cur
        #cur //= r
    return out

#for n in range(1, 676 + 26 + 2):
if True:
    out = answer(n)
    #print(n, out)
    print(out)
Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

n, m = map(int, input().split(" "))

graph = {}
for node in range(1, n+1):
    graph[node] = []

for i in range(m):
    a, b = map(int, input().split(" "))
    graph[a].append(b)
    graph[b].append(a)

#print("graph", graph)

michi = [None] * (n+1)
uses = [False] * (n+1)

def set(x):
    return x
def f(pnode, cur_node):
    michi[cur_node] = pnode
    ret = set([(cur_node, child_node) for child_node in graph[cur_node] if child_node != pnode])
    return ret

uses[1] = True
pnode = -1
cur_node = 1
cur_nodes= set([(cur_node, child_node) for child_node in graph[cur_node] if child_node != pnode])
depth = 1
while True:
    next_nodes = set([])
    done = False
    for pnode, cur_node in cur_nodes:
        if not uses[cur_node]:
            ret = f(pnode, cur_node)
            next_nodes = next_nodes + ret
            #next_nodes = next_nodes | ret
            uses[cur_node] = True
            done = True

    #print(done, depth, next_nodes)
    #print("uses", uses)
    if not done:
        break
    depth += 1
    cur_nodes = next_nodes

michi = michi[2:]
if None in michi:
    print("No")
else:
    print("Yes")
    for node in michi:
        print(node)

Fixed submission:
#input = raw_input

n, m = map(int, input().split(" "))

graph = {}
for node in range(1, n+1):
    graph[node] = []

for i in range(m):
    a, b = map(int, input().split(" "))
    graph[a].append(b)
    graph[b].append(a)

#print("graph", graph)

michi = [None] * (n+1)
uses = [False] * (n+1)

def set(x):
    return x

uses[1] = True

cur_node = 1
cur_nodes = {}
child_nodes = graph[cur_node]
for child_node in child_nodes:
    cur_nodes[child_node] = cur_node
depth = 1
while True:
    next_nodes = {}
    done = False
    for cur_node, pnode in cur_nodes.items():
        if not uses[cur_node]:
            michi[cur_node] = pnode
            uses[cur_node] = True
            for child_node in graph[cur_node]:
                if child_node == pnode or uses[child_node]:
                    continue
                next_nodes[child_node] = cur_node
            done = True

    if not done:
        break
    depth += 1
    cur_nodes = next_nodes
    #print("michi", michi[1:])

michi = michi[2:]
if None in michi:
    print("No")
else:
    print("Yes")
    for node in michi:
        print(node)
Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

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

out = 0
d = 1
while True:
    if d >= n:
        break
    i0 = 0
    i1 = d
    while True:
        if As[i0] + As[i1] == d:
            out += 1

        i0 += 1 
        i1 += 1 
        if i1 >= n:
            break
    
    d += 1

print(out)

Fixed submission:
input = raw_input

from collections import Counter
n = int(input())
As = map(int, input().split(" "))

Bs = [i-A for i, A in enumerate(As)]

c = Counter(Bs)
out = 0
for i in range(n):
    key = As[i] + i 
    cur_out = c[key]
    out += cur_out

print(out)
Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

M = 2019
s = input()
n = len(s)
s = int(s)

div = 10

counts = [0] * M
m = 1
for i in range(n+1):
    j = (s % m) % M
    counts[j] += 1
    m *= 10

out = 0
for c in counts:
    out += (c * (c-1) // 2)

print(out)

Fixed submission:
input = raw_input

M = 2019
s = input()
#n = len(s)
#s = int(s)

div = 10

counts = [0] * M
#m = 1

counts[0] += 1
cur = 0

m = 1
for c in reversed(s):
    cur = (int(c) * m + cur) % M
    counts[cur] += 1
    m = (m * 10) % M
    #m *= 10

out = 0
for c in counts:
    out += (c * (c-1) // 2)

print(out)

Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

M = 2019
s = input()
n = len(s)
s = int(s)

div = 10
cumsum = [s % (10 ** i) for i in range(n+1)]
out = 0
for i in range(n+1):
    for j in range(i+1, n+1):
        if (cumsum[j] - cumsum[i]) % M == 0:
            out += 1


print(out)

Fixed submission:
input = raw_input

M = 2019
s = input()
#n = len(s)
#s = int(s)

div = 10

counts = [0] * M
#m = 1

counts[0] += 1
cur = 0

m = 1
for c in reversed(s):
    cur = (int(c) * m + cur) % M
    counts[cur] += 1
    m = (m * 10) % M
    #m *= 10

out = 0
for c in counts:
    out += (c * (c-1) // 2)

print(out)

Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

M = 2019
s = input()
n = len(s)
s = list(s)

#X = {}
counts = [0] * M
counts_tmp = [0] * M

inv10 = 202

out = 0
for i in range(n):
    c = int(s[i])

    new_counts = [0] * M
    for j in range(M):
        j2 = (j * 10 + c) % M
        new_counts[j2] += counts[j]
    counts = new_counts
    
    c = int(s[i])
    counts[c] += 1
    out += counts[0]

#print(counts, sum(counts))

print(out)

Fixed submission:
input = raw_input

M = 2019
s = input()
#n = len(s)
#s = int(s)

div = 10

counts = [0] * M
#m = 1

counts[0] += 1
cur = 0

m = 1
for c in reversed(s):
    cur = (int(c) * m + cur) % M
    counts[cur] += 1
    m = (m * 10) % M
    #m *= 10

out = 0
for c in counts:
    out += (c * (c-1) // 2)

print(out)

Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

M = 2019
s = input()
n = len(s)
s = list(s)

out = 0
for i in range(n): 
    cur = 0
    for j in range(i, n):
        cur = cur * 10 + int(s[j])
        cur = cur % M
        if cur % M == 0:
            out += 1

print(out)

Fixed submission:
input = raw_input

M = 2019
s = input()
#n = len(s)
#s = int(s)

div = 10

counts = [0] * M
#m = 1

counts[0] += 1
cur = 0

m = 1
for c in reversed(s):
    cur = (int(c) * m + cur) % M
    counts[cur] += 1
    m = (m * 10) % M
    #m *= 10

out = 0
for c in counts:
    out += (c * (c-1) // 2)

print(out)
Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input
n, k = map(int, input().split(" "))
ps = map(int, input().split(" "))

means = [(1+p)/2. for p in ps]

for i in range(n-k+1):
    cur = sum(means[i:i+k])
    if i == 0:
        out = cur
    else:
        out = max(cur, out)

print(out)

Fixed submission:
input = raw_input
n, k = map(int, input().split(" "))
ps = map(int, input().split(" "))

means = [(1+p)/2. for p in ps]

for i in range(n-k+1):
    if i == 0:
        cur = sum(means[i:i+k])
        out = cur
    else:
        cur = cur - means[i-1] + means[i+k-1]
        out = max(cur, out)

print(out)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split(" "))

pairs = []
ratios = []
a_list = []
inputs = []
for i in range(n):
    a, b = map(int, input().split(" "))
    a_list.append(a)
    #ratio = a/b
    #ratios.append(ratio)
    #pairs.append([a, b, ratio])
    inputs.append([a, b])

#pairs = sorted(pairs, key=lambda x: -x[2])
#print(pairs)

max_a = max(a_list)

min_val = -1-max_a
costs = {}
for i in range(min_val, h+1):
    costs[i] = None
costs[h] = 0
#costs = [None for i in range(h)] + [0]

for val in range(h, min_val-1, -1):
    for a, b in inputs:
        if val+a > h:
            continue
        if costs[val+a] is None:
            continue

        if costs[val] is not None:
            costs[val] = min(costs[val+a]+b, costs[val])
        else:
            costs[val] = costs[val+a]+b

out = min([costs[val] for val in range(min_val, 1) if costs[val] is not None])
#print(costs)
print(out)

Fixed submission:
input = raw_input
range = xrange
h, n = map(int, input().split(" "))

pairs = []
ratios = []
a_list = []
inputs = []
for i in range(n):
    a, b = map(int, input().split(" "))
    a_list.append(a)
    #ratio = a/b
    #ratios.append(ratio)
    #pairs.append([a, b, ratio])
    inputs.append([a, b])

#pairs = sorted(pairs, key=lambda x: -x[2])
#print(pairs)

max_a = max(a_list)

min_val = -1-max_a
costs = {}
for i in range(min_val, h+1):
    costs[i] = None
costs[h] = 0
#costs = [None for i in range(h)] + [0]

for val in range(h, min_val-1, -1):
    for a, b in inputs:
        if val+a > h:
            continue
        if costs[val+a] is None:
            continue

        if costs[val] is not None:
            costs[val] = min(costs[val+a]+b, costs[val])
        else:
            costs[val] = costs[val+a]+b

out = min([costs[val] for val in range(min_val, 1) if costs[val] is not None])
#print(costs)
print(out)
Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input


def answer():
    n, m, v, p = map(int, input().split(" "))
    nums = sorted(map(int, input().split(" ")), reverse=True)

    num_last = nums[p-1]

    nokori_sum = sum(nums[p-1:n])

    out = p
    count = 0
    if v > p:
        for i in range(p, n):
            x = nums[i]
            if x + m < num_last:
                break

            #nokori_yoyuu = ( (x + m) * (n-p+1- 1) ) - (nokori_sum-x)
            nokori_yoyuu = 0
            for j in range(p-1, n):
                if j == i:
                    continue
                x2 = nums[j]
                cur_yoyuu = max(0, min(x+m-x2, m))
                nokori_yoyuu += cur_yoyuu
            cost = (v-p) * m
            if cost > nokori_yoyuu:
                break

            count += 1

        out += count

    else:
        for x in nums[p:]:
            if x + m < num_last:
                break
            count += 1
        out += count

    print(out)

answer()

Fixed submission:
input = raw_input


def answer():
    n, m, v, p = map(int, input().split(" "))
    nums = sorted(map(int, input().split(" ")), reverse=True)

    num_last = nums[p-1]

    nokori_sum = sum(nums[p-1:n])

    out = p
    count = 0
    if v > p:
        cumsum = {}
        cur = 0
        
        cur = 0
        for i in range(p-1, n):
            x = nums[i]
            cur += x
            cumsum[i] = cur

        for i in range(p, n):
            x = nums[i]
            if x + m < num_last:
                break

            #nokori_yoyuu = ( (x + m) * (n-p+1- 1) ) - (nokori_sum-x)
            #nokori_yoyuu = 0
            #for j in range(p-1, n):
            #    if j == i:
            #        continue
            #    x2 = nums[j]
            #    cur_yoyuu = max(0, min(x+m-x2, m))
            #    nokori_yoyuu += cur_yoyuu

            area1 = (x+m) * (i-p+1) - cumsum[i-1]
            #print("n", n, "i", i, "m", m)
            area2 = (n - i - 1) * m
            #print(area1, area2, nokori_yoyuu)

            nokori_yoyuu = area1 + area2

            cost = (v-p) * m
            if cost > nokori_yoyuu:
                break

            count += 1

        out += count

    else:
        for x in nums[p:]:
            if x + m < num_last:
                break
            count += 1
        out += count

    print(out)

answer()
Buggy python submission (verdict: Runtime Error):
n = int(input())
vals = map(int, input().split(" "))
cur_vals = [-1, -1, -1]

M = 1000000007
out = 1
for val in vals:
    before_val = val-1
    before_val_num = sum([1 for cur_val in cur_vals if cur_val == before_val])
    out = (out * before_val_num) % M
    tar_i = cur_vals.index(before_val)
    cur_vals[tar_i] = val

print(out)

Fixed submission:
n = int(input())
vals = map(int, input().split(" "))
cur_vals = [-1, -1, -1]

M = 1000000007
out = 1
for val in vals:
    before_val = val-1
    before_val_num = sum([1 for cur_val in cur_vals if cur_val == before_val])
    if before_val_num == 0:
        out = 0
        break
    out = (out * before_val_num) % M
    tar_i = cur_vals.index(before_val)
    cur_vals[tar_i] = val

print(out)
Buggy python submission (verdict: Runtime Error):
#import math

input = raw_input
n = int(input())

as = list(map(int, input().split(" ")))
sa = sum(as)
#half_sa= sa // 2 if sa % 2 == 0 else (sa // 2) + 1
half_sa = sa // 2

cur_val = 0
for i, a in enumerate(as):
    cur_val += a
    if half_sa <= cur_val:
        over_i = i # made
        break

cur_val2 = cur_val
cur_val1 = cur_val - a

#print(cur_val1, half_sa, cur_val2)
diff1 = half_sa - cur_val1
diff2 = cur_val2 - half_sa

val_a = cur_val1
val_b = sa - val_a

val_c = cur_val2
val_d = sa - val_c

out = min(val_b-val_a, val_c - val_d)

#if diff1 <= diff2:
#    #half_sa = int(math.floor(half_sa))
#    out = diff1
#else:
#    out = diff2
print(out)

Fixed submission:
#import math

#input = raw_input
n = int(input())

As = list(map(int, input().split(" ")))
sA = sum(As)
#half_sA= sA // 2 if sA % 2 == 0 else (sA // 2) + 1
half_sA = sA // 2

cur_val = 0
for i, a in enumerate(As):
    cur_val += a
    if half_sA <= cur_val:
        over_i = i # made
        break

cur_val2 = cur_val
cur_val1 = cur_val - a

#print(cur_val1, half_sA, cur_val2)
diff1 = half_sA - cur_val1
diff2 = cur_val2 - half_sA

val_a = cur_val1
val_b = sA - val_a

val_c = cur_val2
val_d = sA - val_c

out = min( abs(val_b-val_a), abs(val_c-val_d) )

#if diff1 <= diff2:
#    #half_sA = int(math.floor(half_sA))
#    out = diff1
#else:
#    out = diff2
print(out)