Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
li = list(map(int, input().split()))

c = sum(li) / 4*M
res = 0
for l in li:
    res += 1 if l >= c
if res == M:
    print('Yes')
else:
    print('No')

Fixed submission:
N, M = map(int,input().split())
li = list(map(int, input().split()))

c = sum(li) / (4*M)
res = 0
for l in li:
    if l >= c:
        res += 1
if res >= M:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
K, N = map(int,input().split())
N = N-1
A = list(map(int, input().split()))
A_d = [ A[i+1]-A[i] for i in range(0, len(A)-1)]
A_d.append(K-A[-1]+A[0])
print(A_d)
A_d2 = (A_d+A_d[1:])*2
print(A_d2)
res = K
for i in range(len(A_d2)-1):
    if res > sum(A_d2[i:i+N]):
        res = sum(A_d2[i:i+N])
print(res)

Fixed submission:
s = input()
if s[2]==s[3] and s[4]==s[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int,input().split()))

count = 0
for i in range(N*K-1):
    for j in range(i+1, N*K):
        B_i = A[i % N]
        B_j = A[j % N]
        if B_i > B_j:
            count += 1
        count %= 1000000007
print(count)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int,input().split()))
MOD = 1000000007
count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if A[i] > A[j]:
            count += 1
first = (count * K) % 1000000007

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1

ans = ((count * K) + (count2 * K * (K-1) // 2)) % MOD
#second = (count2 * (K*(K-1)/2)%MOD) % MOD

#print(int((first+second)%MOD))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int,input().split()))

i = 0
D = 0
while D <= X and i <= N:
    D += L[i]
    i += 1
print(i)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int,input().split()))

count = 1
D = 0
for i in range(N):
  D += L[i]
  if D <= X:
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
#import numpy as np
#N = map(int, input().split())
N = int(input())
h = list(map(int,input().split()))

# DP問題はメモ化再帰
#memo = np.full(N, -1)
memo = [-1]*N
def func(i):
    if memo[i] != -1:
        return memo[i]
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1]-h[0])
    a = func(i-1) + abs(h[i]-h[i-1])
    b = func(i-2) + abs(h[i]-h[i-2])
    memo[i] = min(a,b)
    return min(a,b)
print(func(N-1))


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
#import numpy as np
#N = map(int, input().split())
N = int(input())
h = list(map(int,input().split()))

# メモ化再帰
#memo = np.full(N, -1)
memo = [-1]*N
def func(i):
    if memo[i] != -1:
        return memo[i]
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1]-h[0])
    a = func(i-1) + abs(h[i]-h[i-1])
    b = func(i-2) + abs(h[i]-h[i-2])
    memo[i] = min(a,b)
    return min(a,b)
print(func(N-1))

# pythonの問題はfuncの呼び出し回数
# 10^50に耐えられない
# sys.setrecursionlimit(10**6)で回避可能
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a_list = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10 ** 5)+1)]

for i in a_list:
    ary[i] += i

ans = []
for _ in range(q):
    b, c = map(int, input().split())
    ary[c] += (ary[b]/b)*c
    ary[b] = 0
    ans.append(int(sum(ary)))

for a in ans:
    print(a)


Fixed submission:
n = int(input())

a_list = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10**5) + 1)]

for i in a_list:
    ary[i] += 1

ans = []

f_ans = sum(a_list)
for _ in range(q):
    b, c = map(int, input().split())
    f_ans += (c-b)*ary[b]
    ary[c] += ary[b]
    ary[b] = 0

    ans.append(f_ans)

for a in ans:
    print(a)

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

a_list = [int(i) for i in input().split()]
q = int(input())

BC_list = []

for _ in range(q):
    tmp = [int(i) for i in input().split()]
    BC_list.append(tmp)

# print(BC_list)

ary = [0 for _ in range((10 ** 5)+1)]

for i in a_list:
    ary[i] += i


for i in BC_list:
    b = i[0]
    c = i[1]
    ary[c] += (ary[b]/b)*c
    ary[b] = 0
    ans = int(sum(ary))
    print(ans)


Fixed submission:
n = int(input())

a_list = [int(i) for i in input().split()]
q = int(input())

ary = [0 for _ in range((10**5) + 1)]

for i in a_list:
    ary[i] += 1

ans = []

f_ans = sum(a_list)
for _ in range(q):
    b, c = map(int, input().split())
    f_ans += (c-b)*ary[b]
    ary[c] += ary[b]
    ary[b] = 0

    ans.append(f_ans)

for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 1
flg = True

if '0' in list(input().split()):
    print(0)
else:
    for a in input().split():
        _a = int(a)
        ans *= _a
        if ans > 10 ** 18:
            print(-1)
            flg = False
            break

    if flg:
        print(ans)


Fixed submission:
n = int(input())
ans = 1
flg = True
input_a = list(input().split())

if '0' in input_a:
    print(0)
else:
    for a in input_a:
        _a = int(a)
        ans *= _a
        if ans > 10 ** 18:
            print(-1)
            flg = False
            break

    if flg:
        print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())
AB = []
H = input().split()
Hall = [1] * N
 
# print(H)
for i in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])
    AH = H[a - 1]
    BH = H[b - 1]
    if AH >= BH:
        Hall[b - 1] = 0
    if BH >= AH:
        Hall[a - 1] = 0
 
 
print(Hall.count(1))
import numpy as np
N, M = map(int, input().split())

Fixed submission:
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
ans = [1] * N


# print(H)

for i in range(M):
    a, b = map(int, input().split())
    AH = H[a - 1]
    BH = H[b - 1]
    # print(AH, BH)
    if AH >= BH:
        ans[b - 1] = 0
    if BH >= AH:
        ans[a - 1] = 0


print(ans.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
H = []
AB = []
H = input().split()

for _ in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])

c = 0

for i in range(N):
    flg = True
    Hi = int(H[i])
    for m in range(M):
        if i + 1 in AB[m]:
            o_idx = 1 - AB[m].index(i + 1)
            otherH = int(H[AB[m][o_idx]-1])
            # print(AB[m], i+1, o_idx, otherH, Hi)
            if Hi <= otherH:
                flg = False
                break

    if flg:
        c += 1
    # print(c)

print(c)


Fixed submission:
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
ans = [1] * N


# print(H)

for i in range(M):
    a, b = map(int, input().split())
    AH = H[a - 1]
    BH = H[b - 1]
    # print(AH, BH)
    if AH >= BH:
        ans[b - 1] = 0
    if BH >= AH:
        ans[a - 1] = 0


print(ans.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
H = []
AB = []
H = input().split()

for _ in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])

c = 0

for i in range(N):
    flg = True
    Hi = int(H[i])
    for m in range(M):
        if i + 1 in AB[m]:
            o_idx = 1 - AB[m].index(i + 1)
            otherH = int(H[AB[m][o_idx]-1])
            # print(AB[m], i+1, o_idx, otherH, Hi)
            if Hi <= otherH:
                flg = False

    if flg:
        c += 1
    # print(c)

print(c)


Fixed submission:
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
ans = [1] * N


# print(H)

for i in range(M):
    a, b = map(int, input().split())
    AH = H[a - 1]
    BH = H[b - 1]
    # print(AH, BH)
    if AH >= BH:
        ans[b - 1] = 0
    if BH >= AH:
        ans[a - 1] = 0


print(ans.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())  # 入力

ans = None
a_max = None

for _x in range(N):
    x = min((B - 1), N) * (_x+1)
    if x > N:
        break
    # print(x)
    a = x/B-int(x / B)
    # print(int(a * A))
    sa = int(a*A)
    # s = int((A * x) / B) - A * int(x / B)
    if a_max == None:
        a_max = sa
    elif sa > a_max:
        a_max = sa

print(a_max)


Fixed submission:
A, B, N = map(int, input().split())  # 入力

ans = None
a_max = None

for _x in range(1):
    x = min((B - 1), N) * (_x+1)
    if x > N:
        break
    # print(x)
    a = x/B-int(x / B)
    # print(int(a * A))
    sa = int(a*A)
    # s = int((A * x) / B) - A * int(x / B)
    if a_max == None:
        a_max = sa
    elif sa > a_max:
        a_max = sa

print(a_max)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())  # 入力

ans = None

for _x in range(N):
    x = _x + 1
    s = int((A * x) / B) - A * int(x / B)
    if ans == None:
        ans = s
    elif s > ans:
        ans = s

print(ans)


Fixed submission:
A, B, N = map(int, input().split())  # 入力

ans = None
a_max = None

for _x in range(1):
    x = min((B - 1), N) * (_x+1)
    if x > N:
        break
    # print(x)
    a = x/B-int(x / B)
    # print(int(a * A))
    sa = int(a*A)
    # s = int((A * x) / B) - A * int(x / B)
    if a_max == None:
        a_max = sa
    elif sa > a_max:
        a_max = sa

print(a_max)
Buggy python submission (verdict: Runtime Error):
in = input()

if in == "T":
  return "A"
if in == "A":
  return "T"
if in == "C":
  return "G"
if in == "G":
  return "C"


Fixed submission:
if __name__ == '__main__':
  V = input()
  
  if V == "T":
  	print("A")
  
  if V == "A":
    print("T")
  
  if V == "C":
    print("G")
  
  if V == "G":
    print("C")
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())

# print(N, S)
ans = N

for i, h in enumerate(range(N)):
    skipflg = False
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    # print(f, l, s)
    nw = 0
    ne = 0
    nw = f.count('W')
    ne = s.count('E')
    # print(nw, ne)
    # for r in f:
    #     if r != 'E':
    #         nw += 1
    #         if nw >= ans:
    #             skipflg = True
    #             break
    #         # print('not e')

    # if skipflg:
    #     break

    # for w in s:
    #     if w != 'W':
    #         ne += 1
    #         if nw+ne >= ans:
    #             skipflg = True
    #             break
    #         # print('not w')

    # if skipflg:
    #     break

    ans = min(ans, nw+ne)

print(ans)


Fixed submission:
a, b = map(int, input().split())  # 入力

ans1 = a + b
ans2 = a - b
ans3 = a * b

print(max(ans1,ans2,ans3))

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())

# print(N, S)
ans = N

for i, h in enumerate(range(N)):
    skipflg = False
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    print(f, l, s)
    nw = 0
    ne = 0
    nw = f.count('W')
    ne = s.count('E')
    print(nw, ne)
    # for r in f:
    #     if r != 'E':
    #         nw += 1
    #         if nw >= ans:
    #             skipflg = True
    #             break
    #         # print('not e')

    # if skipflg:
    #     break

    # for w in s:
    #     if w != 'W':
    #         ne += 1
    #         if nw+ne >= ans:
    #             skipflg = True
    #             break
    #         # print('not w')

    # if skipflg:
    #     break

    ans = min(ans, nw+ne)

print(ans)


Fixed submission:
a, b = map(int, input().split())  # 入力

ans1 = a + b
ans2 = a - b
ans3 = a * b

print(max(ans1,ans2,ans3))
Buggy python submission (verdict: Runtime Error):
x = input()
max1 = 1
for s in range(x):
  for t in range(x):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)



Fixed submission:
x = int(input())
max1 = 1
for s in range(x):
  for t in range(2,10):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)

Buggy python submission (verdict: Runtime Error):
x = map(int, input().split())
max1 = 1
for s in range(x):
  for t in range(x):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)



Fixed submission:
x = int(input())
max1 = 1
for s in range(x):
  for t in range(2,10):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)

Buggy python submission (verdict: Runtime Error):
x = map(int, input().split())
max1 = 1
for s in range(100):
  for t in range(100):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)



Fixed submission:
x = int(input())
max1 = 1
for s in range(x):
  for t in range(2,10):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)

Buggy python submission (verdict: Runtime Error):
x = map(int, input().split())
max1 = 1
for s in range(100):
  for t in range(100):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
    


print(max1)

Fixed submission:
x = int(input())
max1 = 1
for s in range(x):
  for t in range(2,10):
    if pow(s,t) > max1 and pow(s,t) <= x:
      max1 = pow(s,t)
print(max1)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())  # 入力
k = int(input())  # 入力
num_ary = [a, b, c]
max_n = max(num_ary)

max_index = num_ary.index(max_n)#最大値のindex

max_num = max_n * pow(2, k)

num_ary[max_index] = max_num

print(num_ary[0] + num_ary[1] + num_ary[2])





Fixed submission:
a, b = map(int, input().split())  # 入力
if a <=  b:
    print(a)
if b < a:
    print(a-1)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())  # 入力
k = map(int, input().split())  # 入力
num_ary = [a, b, c]
max_n = max(a,b,c)
max_index = num_ary.index(max_n)#最大値のindex
max_num = pow(max(a, b, c), k)

num_ary[max_index] = max_num

print(num_ary[0] + num_ary[1] + num_ary[2])





Fixed submission:
a, b, c = map(int, input().split())  # 入力
k = int(input())  # 入力
num_ary = [a, b, c]
max_n = max(num_ary)

max_index = num_ary.index(max_n)#最大値のindex

max_num = max_n * pow(2, k)

num_ary[max_index] = max_num

print(num_ary[0] + num_ary[1] + num_ary[2])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
operation = [list(map(int, input().split())) for _ in range(q)]

from  collections import Counter

dict_a = Counter(a)

def answer(q, dict_a):
  for i in range(q):
    dict_a[operation[i][1]] += dict_a[operation[i][0]]
    dict_a[operation[i][0]] = 0
    s = 0
    for (k, v) in dict_a.items():
      s += k*v
    print(s)

answer(q, dict_a)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

from  collections import Counter

dict_a = Counter(a)
s = sum(a)

for i in range(q):
  b, c = map(int, input().split())
  s -= b*dict_a[b]
  s += c*dict_a[b]
  dict_a[c] += dict_a[b]
  dict_a[b] = 0
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
operation = [list(map(int, input().split())) for _ in range(q)]

from  collections import Counter

dict_a = Counter(a)

for i in range(q):
  dict_a[operation[i][1]] += dict_a[operation[i][0]]
  dict_a[operation[i][0]] = 0
  s = 0
  for (k, v) in dict_a.items():
    s += k*v
  print(s)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

from  collections import Counter

dict_a = Counter(a)
s = sum(a)

for i in range(q):
  b, c = map(int, input().split())
  s -= b*dict_a[b]
  s += c*dict_a[b]
  dict_a[c] += dict_a[b]
  dict_a[b] = 0
  print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
operation = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
  a = [operation[i][1] if num == operation[i][0] else num for num in a]
  print(sum(a))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

from  collections import Counter

dict_a = Counter(a)
s = sum(a)

for i in range(q):
  b, c = map(int, input().split())
  s -= b*dict_a[b]
  s += c*dict_a[b]
  dict_a[c] += dict_a[b]
  dict_a[b] = 0
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num_list = map(int, input().split())

a = 1
for x in num_list:
  a = a * x
if a > 1000000000000000000:
  print("-1")
else:
	print(a)

Fixed submission:
n = int(input())
num_list = list(map(int, input().split()))
     
a = 1
if 0 in num_list:
    print(0)
else:
    for x in num_list:
        a = a * x
        if (a > 1000000000000000000):
            print("-1")
            break
    if (a <= 1000000000000000000):
      print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mentors = input().split(" ")

for i in range(1, n+1):
    print(mentors.count(str(i)))

Fixed submission:
import collections

n = int(input())
mentors = input().split(" ")

a = collections.Counter(mentors)

for i in range(1, n+1):
    if str(i) in a.keys():
        print(a[str(i)])
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mentors = input().split(" ")
mentors = [int(mentors[i]) for i in range(len(mentors))] 

for i in range(1, n+1):
    print(mentors.count(i))

Fixed submission:
import collections

n = int(input())
mentors = input().split(" ")

a = collections.Counter(mentors)

for i in range(1, n+1):
    if str(i) in a.keys():
        print(a[str(i)])
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
x = input()
for i in range(len(x)):
  if x[i] == "7":
    return "Yes"

Fixed submission:
x = input()
if ("7" in x) == True:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = input()

if s[2] == s[3] & s[4] == s[5]:
  print("Yes")
else:
  print("No")

Fixed submission:
s = input()
     
if (s[2] == s[3]) & (s[4] == s[5]):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

for num in b:
  for x in range(3):
    for y in range(3):
      if a[x][y] == num:
        a[x][y] = 0

if sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[3]) == 0:
  print("Yes")
elif sum([a[0][0],a[1][1],a[2][2]]) == 0 or sum([a[2][0],a[1][1],a[0][2]]):
  print("Yes")
elif sum([a[0][0],a[1][0],a[2][0]]) == 0 or sum([a[0][1],a[1][1],a[2][1]]) == 0 or sum([a[0][2],a[1][2],a[2][2]]) == 0:
  print("Yes")                                                 
else:
  print("No")

Fixed submission:
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

for num in b:
  for x in range(3):
    for y in range(3):
      if a[x][y] == num:
        a[x][y] = 0

if sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2]) == 0:
  print("Yes")
elif sum([a[0][0],a[1][1],a[2][2]]) == 0 or sum([a[2][0],a[1][1],a[0][2]]) == 0:
  print("Yes")
elif sum([a[0][0],a[1][0],a[2][0]]) == 0 or sum([a[0][1],a[1][1],a[2][1]]) == 0 or sum([a[0][2],a[1][2],a[2][2]]) == 0:
  print("Yes")                                                 
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

s = []
for i in range(n):
  s.append(abs(sum(a[:i])*2-sum(a)))

print(min(s))

Fixed submission:
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))))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if sum(a)/2 == sum(a[:(n//2)]):
  print(0)
elif sum(a)/2 >= sum(a[:(n//2)]):
  x = 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))))


Fixed submission:
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))))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
  if sum(a)/2 <= sum(a[:i]):
    x = i
    break
    
print(sum(a[:x])*2 - sum(a))

Fixed submission:
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))))
Buggy python submission (verdict: Runtime Error):
j = 0
for n in s:
  if n == "a":
    if i + j < a + b:
      i += 1
      print("Yes")
    else:
      print("No")
  elif n == "b":
    if (i + j < a + b) and j < b:
      j += 1
      print("Yes")
    else:
      print("No")
  else:
    print("No")


Fixed submission:
n, a, b = map(int, input().split())
s = input()

i = 0
j = 0
for n in s:
  if n == "a":
    if i + j < a + b:
      i += 1
      print("Yes")
    else:
      print("No")
  elif n == "b":
    if (i + j < a + b) and j < b:
      j += 1
      print("Yes")
    else:
      print("No")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = input()
num = list(map(int,input().split()))
for l in range(n):
    ans *= num[l] 
    if ans >= 10**18:
        print(-1)
        return
print(ans)

Fixed submission:
# %%
def main():
    N = input()
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
num = list(map(int,input().split()))
for l in range(len(num)):
    ans *= num[l] 
if ans < 10**18:
    print(ans)
elif ans >= 10**18:
    print(-1)

Fixed submission:
# %%
def main():
    N = input()
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
s = 0
if  a + b >= k:
    s = a
else:
    s = a - (c - b) 
print(s)


Fixed submission:
s = input()
t = input()
if t.startswith(s) == 1:
    print("Yes")
else:
    print("No")