Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())

cnt = 0
for X in range(K+1):
  for Y in range(K+1):
    Z = S - X - Y
    if 0 <= X <= K and 0 <= Y <= K and 0 <= Z <= K and X + Y + Z == S:
      cnt += 1

print(cnt)

Fixed submission:
K, S = map(int, input().split())

cnt = 0
for x in range(K + 1):
  for y in range(K + 1):
    z = S - x - y
    if 0 <= z <= K:
      cnt += 1
      
print(cnt)
Buggy python submission (verdict: Runtime Error):
fS = input()
n = len(S)

def dfs(i, f):
  if i == n - 1:
    return sum(list(map(int, f.split('+'))))
  
  return dfs(i+1, f+S[i+1]) + dfs(i+1, f+'+'+S[i+1]) 

print(dfs(0, S[0]))

Fixed submission:
S = input()
n = len(S)

def dfs(i, f):
  if i == n - 1:
    return sum(list(map(int, f.split('+'))))

  return dfs(i+1, f+S[i+1]) + dfs(i+1, f+'+'+S[i+1])

print(dfs(0, S[0]))
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

count = 0
now_a = 0
now_b = 0
while k > 0 and a[now_a] < k or b[now_b] < k:
  if a[0] > b[0] and now_a > len(a) or now_b < len(b):
    k -= b[now_b]
    now_b += 1
  else:
    k -= a[now_a]
    now_a += 1
  count += 1
  
print (count)

Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
_sum = 0

for i in range(n):
  a.append(a[i] + A[i])
for i in range(m):
  b.append(b[i] + B[i])
  
j = m
counts = [0]
for i in range(n + 1):
  if (a[i] > k):
    break
  while b[j] > k - a[i]:
    j -= 1
  counts.append(i + j)
  
print (max(counts))
Buggy python submission (verdict: Time Limit Exceeded):
def calc(b, c):
  _sum = 0
  for i in range(n):
    a[i] = c if a[i] == b else a[i]
    _sum += a[i]
  return _sum

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
  b, c = map(int, input().split())
  print (calc(b, c))

Fixed submission:
_counts = [0 for i in range(100001)]
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  _counts[a[i]] += 1
_sum = sum(a)
q = int(input())

for i in range(q):
  b, c = map(int, input().split())
  _sum += (c - b) * _counts[b]
  print (_sum)
  _counts[c] += _counts[b]
  _counts[b] = 0
Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, n = map(int, input().split())
ans = []
for i in range (n):
  s = math.floor((a * (i + 1)) / b) - a * math.floor((i + 1) / b)
  ans.append(s)
  if max(ans) > s:
    break
print (max(ans))

Fixed submission:
import math
a, b, n = map(int, input().split())
ans = []

def Calcf(i):
  return math.floor((a * i) / b) - a * math.floor(i / b)
    
print (Calcf(min(b - 1, n)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = ["" for i in range(n)]
ans = 0
for i in range(n):
  a = input()
  if a not in s:
    s[i] = a
    ans += 1
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
print(len(set(s)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
ans = 0
for i in range(n):
  a = input()
  count = 0 if a in s else 1
  s.append(a)
  ans += count
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
print(len(set(s)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int,input().split()))
ans = 0
for i in range(0,len(arr)+1,2):
    if arr[i] % 2 != 0:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
ans = 0
for i in range(0,len(arr)+(n%2),2):
    if arr[i] % 2 != 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
an = list(map(int,input().split()))
for i in an:
    if i == 0:
        ans = 0
if ans != 0:
    for i in range(n):
        ans = ans * an[i]
        if ans > 10**18:
            ans = -1
print(ans)

Fixed submission:
n = int(input())
ans = 1
an = list(map(int,input().split()))
for i in an:
    if i == 0:
        ans = 0
if ans != 0:
    for i in range(n):
        ans = ans * an[i]
        if ans > 10**18:
            ans = -1
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
an = list(map(int,input().split()))
for i in range(n):
    ans = ans * an[i]
if ans > 10**18:
    ans = -1
print(ans)

Fixed submission:
n = int(input())
ans = 1
an = list(map(int,input().split()))
for i in an:
    if i == 0:
        ans = 0
if ans != 0:
    for i in range(n):
        ans = ans * an[i]
        if ans > 10**18:
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
#"tel"は既に訪れている町
tel = set()
route = []
#"town"は今いる町
town = 1
route.append(town)
tel.add(town)
time_loop = 0
for i in range(k):
    town = a[town-1]
    if town in tel:
        time_loop += 1
        break
    tel.add(town)
    route.append(town)
    #テレポートした回数をカウント
    time_loop += 1

#"start"は"route"内のループの起点のとなる町のインデックス番号
start = route.index(town)
k = (k - start) % (time_loop - start)
print(route[k+start])




Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
#"tel"は既に訪れている町
tel = set()
route = []
#"town"は今いる町
town = 1
route.append(town)
tel.add(town)
time_loop = 0
for i in range(k):
    town = a[town-1]
    if town in tel:
        time_loop += 1
        break
    tel.add(town)
    route.append(town)
    #テレポートした回数をカウント
    time_loop += 1

#"start"は"route"内のループの起点のとなる町のインデックス番号
start = route.index(town)
if time_loop != start:
    k = (k - start) % (time_loop - start)
    print(route[k+start])
else:
    print(town)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

answer = 0
N = int(input())
for a in range(1,N+1):
    for b in range(1,N+1):
        for c in range(1,N+1):
            answer += gcd(a,b,c)
            
print(answer)

Fixed submission:
from math import gcd

K = int(input())
ans=0
array = [0] * 201

for X in range(1,K+1):
    for c in range(1,K+1):
        array[X] += gcd(X,c)

for a in range(1,K+1):
    for b in range(1,K+1):
        X = gcd(a,b)
        ans += array[X]

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
Ai = list(map(int,input().split()))
Ai.sort(reverse=True)
x = sum(Ai[0:M])
soutokuhyou = sum(Ai[:])
seigen = soutokuhyou / (4*M)
if Ai[M] < seigen:
    print("No")
else:
    print("Yes")

Fixed submission:
N,M = map(int,input().split())
Ai = list(map(int,input().split()))
Ai.sort(reverse=True)
soutokuhyou = sum(Ai[:])
seigen = soutokuhyou / (4*M)
if Ai[M-1] < seigen:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
c=1
for b in range(1,x):
    for p in range(2,x):
        if b**p<=x:
            c=max(c,b**p)
print(c)

Fixed submission:
x = int(input())
c=1
for b in range(1,x):
    for p in range(2,x):
        if b**p<=x:
            c=max(c,b**p)
        else:break
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
for i in range(1,n+1):
    ans *= i
print(ans%(10**9+7))

Fixed submission:
import math
print(math.factorial(int(input()))%(10**9+7))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

a = Counter(s)
print(type(a))
b = a.most_common()[0][1]

s = list(set(s)) #sの重複した要素を消す


for i in s:
    if s[i] == b:
        print(i)


Fixed submission:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

a = Counter(s)

b = a.most_common()[0][1]

s = list(set(s)) #sの重複した要素を消す
s.sort()

for i in s:
    if a[i] == b:
        print(i)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

a = Counter(s)
b = a.most_common()[0][1]

s = list(set(s)) #sの重複した要素を消す

print(a[])

for i in s:
    if a[i] == b:
        print(i)

Fixed submission:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]

a = Counter(s)

b = a.most_common()[0][1]

s = list(set(s)) #sの重複した要素を消す
s.sort()

for i in s:
    if a[i] == b:
        print(i)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int.input().split()))
c = Counter(a)

if c.most_common()[0][1] == 1:
    print("Yes")
else:
    print("No")

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)

if c.most_common()[0][1] == 1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
sys.stdout = open("output.txt",'w')
sys.stdin = open("input.txt",'r')
import math
def gcd(a,b):
	if a == 0:
		return b
	return gcd(b%a,a)

def main():
	n,x,t = map(int,input().split())
	print((math.ceil(n/x))*t)
if __name__ == "__main__":
	main()


	


Fixed submission:
import sys

import math
def gcd(a,b):
	if a == 0:
		return b
	return gcd(b%a,a)

def main():
	n,x,t = map(int,input().split())
	print((math.ceil(n/x))*t)
if __name__ == "__main__":
	main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d=0
while n>0:
    d+=n%10
    n//=10
if d%9 == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = input()
d=0
for i in range(len(n)):
    d+=int(n[i])
if d%9 == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())-1
a=list(map(int,input().split()))
r=[]
for i in range(n):
  	r.append(0)
    r[a[i]-1]+=1
for i in range (n):
    print (r[i])
print (0)

Fixed submission:
n=int(input())-1
a=list(map(int,input().split()))
r=[]
for i in range(n):
    r.append(0)
    r[a[i]-1]+=1
for i in range (n):
    print (r[i])
print (0)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
for i in range (n):
    print (a.count(i+1))

Fixed submission:
n=int(input())-1
a=list(map(int,input().split()))
r=[]
for i in range(n):
    r.append(0)
    r[a[i]-1]+=1
for i in range (n):
    print (r[i])
print (0)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n):
    lFlag=True
    for j in range(i):
        if (p[i]>p[j]):
            lFlag=False
            break
    if lFlag:
        c=c+1
print(c)


Fixed submission:
n=int(input())
p=list(map(int,input().split()))
c=0
min=2*10**5
for i in range(n):
    if (p[i]<=min):
        c=c+1
    if p[i]<min:
        min=p[i]
print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())

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

s=0

for i in range(len(x)):

	s+=x[i]i=0

l=0

while (l<(s//2)):

	l+=x[i]

	i+=1

r=abs((s-l)-l) 

i=len(x)-1

l=0

while(l<(s//2)):

	l+=x[i]

	i-=1

if abs((s-l)-l)<r:

	r=abs((s-l)-l) 

print (r)

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

s=0
for i in range(len(x)):
	s+=x[i]
i=0
l=0
while (l<(s//2)):
	l+=x[i]
	i+=1
r=abs(s-l-l) 
i=len(x)-1
l=0
while(l<(s//2)):
	l+=x[i]
	i-=1
if abs((s-l)-l)<r:
	r=abs(s-l-l) 
print (r)
Buggy python submission (verdict: Runtime Error):
n=int(input())
r=n-1
for i in range(int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)


Fixed submission:
n=int(input())
r=n-1
for i in range(1,int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)

Buggy python submission (verdict: Runtime Error):
=int(input())
r=n-1
for i in range(2,int(n**0.5)):
    if (n%i==0):
        s=n//i+i-2
        if s<r:
            r=s
print(r)


Fixed submission:
n=int(input())
r=n-1
for i in range(1,int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)

Buggy python submission (verdict: Runtime Error):
n=int(input()) 
r=False
i=2
m=n-1
i=2
while (i<=int(n**0.5)):
	if ((n%i)==0 ):		
        s=i+n//i-2
		if (s<m):
			m=s
	i+=1
print(m)

Fixed submission:
n=int(input())
r=n-1
for i in range(1,int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    m = A[0]
    S = 0
 
    for a in A:
        if m - a > 0:
            S += m - a
        if m < a:
            m = a
    
    print(S)
 
 
if __name__ == "__main__":
    main()

Fixed submission:
import math

line = input()

strL = line.split()

N = int(strL[0])
X = int(strL[1])
T = int(strL[2])

ans = math.ceil(N/X) * T

print(ans)
Buggy python submission (verdict: Runtime Error):
import re
print("YES" if re.match("^(dream|dreamer|erase|eraser)+$"), input() else "NO")


Fixed submission:
import re
s = input()
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
print('YES' if len(s) == 0 else 'NO')
Buggy python submission (verdict: Runtime Error):
N, X, T  = map(int,input))
ans = (N//X + N%X)*T
print(ans)

Fixed submission:
N, X, T  = map(int,input().split())
if N%X == 0:
  print( N//X *T )
else:
  print( ( N//X + 1)*T )
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = A[0]
r = A[K]
for i in range(K-2):
  if l < r:
    print('Yes')
  else:
    print('No')
  l = A[1+i]
  r = A[K+1+i]
if l < r:
  print('Yes')
else:
  print('No')

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = A[0]
r = A[K]
for i in range(1,N-K):
  if l < r:
    print('Yes')
  else:
    print('No')
  l = A[i]
  r = A[K+i]
if l < r:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = A[0]
r = A[K]
for i in range(K-2):
  if l < r:
    print(l,r)
    print('Yes')
  else:
    print(l,r)
    print('No')
  l = A[1+i]
  r = A[K+1+i]
if l < r:
  print('Yes')
else:
  print('No')

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = A[0]
r = A[K]
for i in range(1,N-K):
  if l < r:
    print('Yes')
  else:
    print('No')
  l = A[i]
  r = A[K+i]
if l < r:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
cnt = 0
for i in range(len(S)):
  if S[i] != T[i]:
    cnt += 1
print(cnt)

Fixed submission:
S = input()
T = input()
cnt = 0
for i in range(len(S)):
  if S[i] != T[i]:
    cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
S, T = input().split()
cnt = 0
for i in range(len(S)):
  if S[i] != T[i]:
    cnt += 1
print(i)

Fixed submission:
S = input()
T = input()
cnt = 0
for i in range(len(S)):
  if S[i] != T[i]:
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
if input().isUpper():
  print('A')
else:
  print('a')

Fixed submission:
if input().isupper():
  print('A')
else:
  print('a')
Buggy python submission (verdict: Runtime Error):
eps = 1.0e-14
if math.sqrt(a) + math.sqrt(b) + eps < math.sqrt(c):
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = map(int,input().split())
#if math.sqrt(a)+math.sqrt(b) < math.sqrt(c):
if c-a-b> 0 and (c-a-b)**2 > 4*a*b:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int,input().split())
#if math.sqrt(a)+math.sqrt(b) < math.sqrt(c):
if a**0.5 + b**0.5 < c**0.5
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = map(int,input().split())
#if math.sqrt(a)+math.sqrt(b) < math.sqrt(c):
if c-a-b> 0 and (c-a-b)**2 > 4*a*b:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
if a**0.5 + b**0.5 < c**0.5
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = map(int,input().split())
#if math.sqrt(a)+math.sqrt(b) < math.sqrt(c):
if c-a-b> 0 and (c-a-b)**2 > 4*a*b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reversed = False
for _ in range(Q):
    q = input().replace(" ","")
    if len(q) == 3:
        t, f, c = q[0],q[1],q[2]
    else:
        t = q[0]
    if t == "1":
        reversed = not reversed
    elif t == "2":
        if f == "1":
            #元の順のとき
            if not reversed:
                S = c + S
            #元とは逆順になっているとき
            else:
                S = S + c
        else:
            #元の順のとき
            if not reversed:
                S = S + c
            #元とは逆順になっているとき
            else:
                S = c + S
if reversed:
    print(S[::-1])
else:
    print(S)

Fixed submission:
S = input()
Q = int(input())
head = ""
tail = ""
reversed = False
for _ in range(Q):
    q = input().replace(" ","")
    if len(q) == 3:
        t, f, c = q[0],q[1],q[2]
    else:
        t = q[0]
    if t == "1":
        reversed = not reversed
    elif t == "2":
        if f == "1":
            #元の順のとき
            if not reversed:
                head = c + head
            #元とは逆順になっているとき
            else:
                tail = tail + c
        else:
            #元の順のとき
            if not reversed:
                tail = tail + c
            #元とは逆順になっているとき
            else:
                head = c + head
if reversed:
    print(tail[::-1],S[::-1],head[::-1],sep="")
else:
    print(head,S,tail,sep="")
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
SC = [-1]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != -1 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c
flg = 1
for i in range(10**(N-1)-1,10**N):
    s = str(i)
    for j in range(1,N+1):
        if SC[j] == -1:
            continue
        if SC[j] != int(s[j-1]):
            flg = 0
            break
    if not flg:
        flg = 1
        continue
    if flg:
        print(i)
        exit()
print(-1)

Fixed submission:
N, M = map(int,input().split())
SC = [-1]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != -1 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c
flg = 1
if N == 1:
    st = 10**(N-1) -1
else:
    st = 10**(N-1)
for i in range(st,10**N):
    s = str(i)
    for j in range(1,N+1):
        if SC[j] == -1:
            continue
        if SC[j] != int(s[j-1]):
            flg = 0
            break
    if not flg:
        flg = 1
        continue
    if flg:
        print(i)
        exit()
print(-1)

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
SC = [-1]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != -1 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c

for i in range(10**(N-1),10**N):
    s = str(i)
    for j in range(1,N+1):
        if SC[j] == -1:
            continue
        if SC[j] != int(s[j-1]):
            flg = 0
            break
    if not flg:
        flg = 1
        continue
    if flg:
        print(i)
        exit()
print(-1)

Fixed submission:
N, M = map(int,input().split())
SC = [-1]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != -1 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c
flg = 1
if N == 1:
    st = 10**(N-1) -1
else:
    st = 10**(N-1)
for i in range(st,10**N):
    s = str(i)
    for j in range(1,N+1):
        if SC[j] == -1:
            continue
        if SC[j] != int(s[j-1]):
            flg = 0
            break
    if not flg:
        flg = 1
        continue
    if flg:
        print(i)
        exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
N,R = map(int,input().split())
if N<=10:
    print(R)
else:
    print(R-100*(10-K))

Fixed submission:
N,R = map(int,input().split())
if N >= 10:
    print(R)
else:
    print(R+100*(10-N))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K+1):
    wa = 0
    for j in range(i,i+K):
        wa += Ex[j]
    maxi = max(maxi,wa)
print(maxi)

Fixed submission:
N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K):
    wa = wa - Ex[i] + Ex[K+i]
    maxi = max(maxi,wa)
print(maxi)
Buggy python submission (verdict: Runtime Error):
import math
def combi(n,r):
    if r > n:return 0
    return math.factorial(n) // (math.factorial(n - r)*(math.factorial(r)))


def solve(i,k,smaller):
    #一番最後の桁まで調べたら終了
    if i == N:
        if k == 0:return 1
        else: 0
    #途中であっても0以外の数字を使い切ったら終了
    if k == 0:return 1

    #Nより小さいことが確定すれば残りの桁数（N-i）のうち
    #k個所に0以外の数字（9**k通り）を使い，それ以外の桁の数字は0なので
    #C(n-i,n-i-k)=C(n-i,k)個所に0をはめる
    if smaller: return combi(N-i, k)*(9**k)
    else:
        #i桁目が0なら，smallerであるといえない
        if S[i] == '0':return solve(i+1,k,False)
        else:
            zero = solve(i+1, k, True)
            aida = solve(i+1, k-1, True) * (int(S[i])-1)
            icchi = solve(i+1, k-1, False)
            return zero + aida + icchi

#0出ない数字がちょうどＫ個であるようなN以下の整数を探索
S = input()
N = len(S)
K = int(input())
print((solve(0,K,False)))

Fixed submission:
import math
def combi(n,r):
    if r > n:return 0
    return math.factorial(n) // (math.factorial(n - r)*(math.factorial(r)))


def solve(i,k,smaller):
    #一番最後の桁まで調べたら終了
    if i == N:
        if k == 0:return 1
        else: return 0

    #途中であっても0以外の数字を使い切ったら終了
    if k == 0:return 1

    #Nより小さいことが確定すれば残りの桁数（N-i）のうち
    #k個所に0以外の数字（9**k通り）を使い，それ以外の桁の数字は0なので
    #C(n-i,n-i-k)=C(n-i,k)個所に0をはめる
    if smaller: return combi(N-i, k)*(9**k)
    else:
        #i桁目が0なら，smallerであるといえない
        if S[i] == '0':return solve(i+1,k,False)
        else:
            zero = solve(i+1, k, True)
            aida = solve(i+1, k-1, True) * (int(S[i])-1)
            icchi = solve(i+1, k-1, False)
            return zero + aida + icchi

#0出ない数字がちょうどＫ個であるようなN以下の整数を探索
S = input()
N = len(S)
K = int(input())
print((solve(0,K,False)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
M = int(input())
if M ==N:
    print("Yes")
else:
    print("No")

Fixed submission:
N,M = map(int,input().split())
if M ==N:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np
import bisect
#input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)
ans = 0
if sumA%2 != 0:
    ans += 1
cumsum = np.cumsum(A)
half = sumA//2
id = bisect.bisect_left(cumsum,half)
mini = min(abs(half-cumsum[id]),abs(cumsum[id+1]-half))
ans += mini
print(ans)

Fixed submission:
import numpy as np
import bisect
N = int(input())
A = list(map(int,input().split()))
sumA = sum(A)
cumsum = np.cumsum(A)
ans = 2020202020
for a in cumsum:
    ans = min(ans,abs(2*a-sumA))
print(ans)
Buggy python submission (verdict: Runtime Error):
1
z

Fixed submission:
N = int(input())
S = input()
if len(S)%2 != 0:
    print("No")
    exit()
if S[:len(S)//2] == S[len(S)//2:]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
mod = 998244353
N = int(input())
A = list(map(int,input().split()))
D = [1 for _ in range(max(A)+1)]
if N == 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

D[1] = A.count(1)
ans = 1
if A[0] > 0 or D[0] > 1:
    print(0)
else:
    for i in range(2,max(A)+1):
        D[i] = A.count(i)
        ans *= (D[i-1]**D[i])%mod
    print(ans)

Fixed submission:
N = int(input())
if N%2 == 0:
    print(N//2 - 1)
else:
    print(N//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(1,10):
    for j in range(1,10):
        if i*j == N:
            print("Yes")
            sys.exit()
print("No")

Fixed submission:
import sys
N = int(input())
for i in range(1,10):
    for j in range(1,10):
        if i*j == N:
            print("Yes")
            sys.exit()
print("No")