Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03745 (python)

Fixed submission:
n = int(input())
num_list = [ int(v) for v in input().split() ]
cut_list = []
status = 0
for i in range(n-1):
    if status == 0:
        if num_list[i+1] > num_list[i]:
            status = 1
        elif num_list[i+1] < num_list[i]:
            status = -1
    elif status == 1:
        if num_list[i+1] < num_list[i]:
            cut_list.append(i)
            status = 0
    elif status == -1:
        if num_list[i+1] > num_list[i]:
            cut_list.append(i)
            status = 0

print(len(cut_list)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
num_list = [ int(v) for v in input().split() ]
mode = 1
ans = 0
for i in range(n-1):
  if mode == 1 and num_list[i+1] < num_list[i]:
  	mode = -1
    ans += 1
  elif mode == -1 and num_list[i+1] > num_list[i]:
  	mode = 1
    ans += 1
  
  
print(ans+1)
Problem p03803 (python)

Fixed submission:
strength = [ str(i) for i in range(2,14) ] + ["1"]
a , b = [ v for v in input().split() ]
if strength.index(a) > strength.index(b):
  print("Alice")
elif strength.index(a) == strength.index(b):
  print("Draw")
else:
  print("Bob")

Buggy submission (verdict: Runtime Error):
strength = [ str(i) for i in range(2,14) ] + ["1"]
a , b = [ v for v in input().split() ]
if a.index(strength) > b.index(strength):
  print("Alice")
elif a.index(strength) == b.index(strength):
  print("Draw")
else:
  print("Bob")
Problem p03839 (python)

Fixed submission:
def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist


n, k = [ int(v) for v in input().split() ]
num = [ int(v) for v in input().split() ]
num_2 = [ max(i,0) for i in num ] 


cum_num, cum_num_2 = [0] + cumsum(num), [0] + cumsum(num_2)

ans = 0
for i in range(n-k+1):
    ansl = cum_num_2[i]
    ansm = cum_num[k+i] - cum_num[i]
    ansr = cum_num_2[n] - cum_num_2[i+k]
    ans = max(ansl+max(ansm,0)+ansr, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = [ int(v) for v in input().split() ]
num = [ int(v) for v in input().split() ]
num_2 = [ max(i,0) for i in num ] 


cum_num, cum_num_2 = [0] + cumsum(num), [0] + cumsum(num_2)

ans = 0
for i in range(n-k+1):
    ansl = cum_num_2[i]
    ansm = cum_num[k+i] - cum_num[i]
    ansr = cum_num_2[n] - cum_num_2[i+k]
    ans = max(ansl+max(ansm,0)+ansr, ans)
print(ans)
Problem p02577 (python)

Fixed submission:
def digitsum(n):
    res = 0
    for i in n:
        #print(ni)
        ni = int(i)
        res += ni
    return res 

s = input()
r = digitsum(s)

if r % 9 == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()

def digitsum(n):
    for i in n:
        ni = int(i)
        res += ni
    return res 

res = digitsum(s)
if res % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02879 (python)

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

if a < 10 and b < 10:
    print(a * b)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())

if a < 10 and b < 10:
    print(a * b)
else:
    print(-1)
Problem p02685 (python)

Fixed submission:
import sys
N,M,K= list(map(int, input().split()))
mod = 998244353

if N == 1:
    print(M)
    sys.exit()


def cmbinit(n):
    fac = [0]*n
    finv = [0]*n
    inv = [0]*n
    fac[0]=fac[1] = 1
    finv[0]=finv[1] = 1
    inv[1] = 1
    for i in range(2,n):
        fac[i] = fac[i-1]*i %mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i]%mod
    
    return fac,finv

def cmb(n,r,fac,finv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0

    return fac[n] * (finv[r] * finv[n - r] % mod) %mod




ans = 0
fac,finv = cmbinit(N)
for k in range(K+1):
    ans += (M * pow(M-1, N-k-1, mod) * cmb(N-1,k,fac,finv))%mod


print(ans%mod)

Buggy submission (verdict: Runtime Error):
N,M,K= list(map(int, input().split()))
mod = 998244353

def cmbinit(n):
    fac = [0]*n
    finv = [0]*n
    inv = [0]*n
    fac[0]=fac[1] = 1
    finv[0]=finv[1] = 1
    inv[1] = 1
    for i in range(2,n):
        fac[i] = fac[i-1]*i %mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i]%mod
    
    return fac,finv

def cmb(n,r,fac,finv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
        
    return fac[n] * (finv[r] * finv[n - r] % mod) %mod




ans = 0
fac,finv = cmbinit(N)
for k in range(K+1):
    ans += (M * pow(M-1, N-k-1, mod) * cmb(N-1,k,fac,finv))%mod


print(ans%mod)

Buggy submission (verdict: Runtime Error):
N,M,K= list(map(int, input().split()))
mod = 998244353

def cmbinit(n):
    fac = [0]*n
    finv = [0]*n
    inv = [0]*n
    fac[0]=fac[1] = 1
    finv[0]=finv[1] = 1
    inv[1] = 1
    for i in range(2,n):
        fac[i] = fac[i-1]*i %mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i]%mod
    
    return fac,finv

def cmb(n,r,fac,finv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    else:
        return fac[n] * (finv[r] * finv[n - r] % mod) %mod




ans = 0
fac,finv = cmbinit(N)
for k in range(K+1):
    ans += (M * pow(M-1, N-k-1, mod) * cmb(N-1,k,fac,finv))%mod


print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(2000)

from math import factorial
N,M,K= list(map(int, input().split()))
mod = 998244353

def cmbinit(n):
    fac = [0]*n
    finv = [0]*n
    inv = [0]*n
    fac[0]=fac[1] = 1
    finv[0]=finv[1] = 1
    inv[1] = 1
    for i in range(2,n):
        fac[i] = fac[i-1]*i %mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i]%mod
    
    return fac,finv

def cmb(n,r,fac,finv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    else:
        return fac[n] * (finv[r] * finv[n - r] % mod) %mod




ans = 0
fac,finv = cmbinit(N)
for k in range(K+1):
    ans += (M * pow(M-1, N-k-1, mod) * cmb(N-1,k,fac,finv))%mod


print(ans%mod)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())

print(6-A-B)

Buggy submission (verdict: Runtime Error):
N = int(input())
S,T = list(input())
S = list(S)
T = list(T)
ans = ''

for i in range(N):
    ans += S[i]+T[i]

print(ans)
Problem p02831 (python)

Fixed submission:
import fractions
A,B = list(map(int, input().split()))

print(A*B//fractions.gcd(A,B))

Buggy submission (verdict: Runtime Error):
import math
A,B = list(map(int, input().split()))

print(A*B//math.gcd(A,B))

Buggy submission (verdict: Runtime Error):
import math
A,B = list(map(int, input().split()))

print(A*B//math.gcd(A,B))
Problem p02835 (python)

Fixed submission:
A1,A2,A3 = list(map(int, input().split()))

if A1+A2+A3 >= 22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
A1,A2,A3 = list(map(int, input().split()))

if A1+A2+A3 => 22:
    print('bust')
else:
    print('win')
Problem p02847 (python)

Fixed submission:
S = input()
L = ['SUN','MON','TUE','WED','THU','FRI','SAT']

print(7-L.index(S))

Buggy submission (verdict: Runtime Error):
import math
A,B,X = list(map(int, input().split()))

def nedan(n):
    return A*n + B*int(math.log10(n)+1)

if nedan(1000000000) <= X:
    print(1000000000)
else:
    min = 0
    max = 1000000000
    while(True):
        if nedan((max+min)//2) <= X:
            min = (max+min)//2
        else:
            max = (max+min)//2
        
        if abs(max-min)<=1:
            break

if nedan(max) <= X:
    print(max)
else:
    print(min)
Problem p02873 (python)

Fixed submission:
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    a_max = max(a)
    ans = a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))

Buggy submission (verdict: Runtime Error):
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    a_max = max(a)
    ans += a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))

Buggy submission (verdict: Runtime Error):
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    ans += a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))
Problem p02915 (python)

Fixed submission:
a = int(input())
print(a*a*a)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
parent = [a[-1]]
rest = a[:-1]

for _ in range(n):
    next_parent = []
    next_rest = []
    for i in parent[::-1]:
        while(rest):
            x = rest.pop()
            if x < i:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    next_rest.reverse()
    rest += next_rest

if len(parent) == 2**n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a = input()
print(a*a*a)

Buggy submission (verdict: Runtime Error):
a = input()
print(a*a*a)

Buggy submission (verdict: Runtime Error):
a = input()
print(a**3)
Problem p02916 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n = int(input())
A = list(map(int,(input().split())))
B = list(map(int,(input().split())))
C = list(map(int,(input().split())))
S = 0
before = 100

for i in range(n):
    S += B[A[i]-1]
    if A[i]-1 == before + 1:
        S += C[before]
    before = A[i]-1

print(S)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = int(input().split())
B = int(input().split())
C = int(input().split())
S = 0
before = 100

for i in range(n):
    S += B[A[i]]
    if A[i] == before + 1:
        S += C[before]
    before = A[i]

print(S)
Problem p02623 (python)

Fixed submission:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
k=M
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d<0:
    for j in reversed(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
  else:
    for j in reversed(range(k)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        k=j+1
        break
    if d<B[0]:
      if c<i+1:
        c=i+1
      k=0
for j in reversed(range(M)):
  if K-B[j]>=0:
    if c<j+1:
      c=j+1
print(c)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()
for i in range(N):
  d=K-A[i]
  if d>=0:
    for j in reversed(range(M)):
      if d>=B[j]:
        if c<i+j+2:
          c=i+j+2
        M=j+1
        break
    if d<B[0]:
      c=i+1
  else:
    for j in reverse(range(M)):
      if K-B[j]>=0:
        if c<j+1:
          c=j+1
        break
    break
print(c)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list()
a=0
b=0
for i in range(N+M):
  if a+1<=N and b+1<=M and A[a]<B[b]:
    C.append(A[a])
    a+=1
  elif a+1<=N and b+1<=M and A[a]>B[b]:
    C.append(B[b])
    b+=1
  elif  a+1<=N and b+1<=M and A[a]==B[b]:
    if a+2==N:
      C.append(B[b])
      b+=1
    elif b+2==M:
      C.append(A[a])
      a+=1
    elif A[a+1]<B[b+1]:
      C.append(A[a])
      a+=1
    else:
      C.append(B[b])
      b+=1
  elif a==N:
    C.append(B[b])
    b+=1
  elif b==M:
    C.append(A[a])
    a+=1
import numpy as np
L=np.array(C).cumsum()
print(len(L[L <= K]))

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list()
a=0
b=0
for i in range(N+M):
  if a+1<=N and b+1<=M and A[a]<B[b]:
    C.append(A[a])
    a+=1
  elif a+1<=N and b+1<=M and A[a]>B[b]:
    C.append(B[b])
    b+=1
  elif  a+1<=N and b+1<=M and A[a]==B[b]:
    if a+2==N:
      C.append(B[b])
      b+=1
    elif b+2==N:
      C.append(A[a])
      a+=1
    elif A[a+1]<B[b+1]:
      C.append(A[a])
      a+=1
    else:
      C.append(B[b])
      b+=1
  elif a==N:
    C.append(B[b])
    b+=1
  elif b==M:
    C.append(A[a])
    a+=1
import numpy as np
L=np.array(C).cumsum()
print(len(L[L <= K]))
Problem p02627 (python)

Fixed submission:
L={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
a=input()
if a in L:
  print("A")
else:
  print("a")

Buggy submission (verdict: Runtime Error):
L=set("A","B")
print(L)
Problem p02629 (python)

Fixed submission:
import numpy as np
N=int(input())
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
A=np.zeros(11,dtype=int)
for i in range(11):
  A[i]=(26**(i+1))
B=np.cumsum(A)
for i in range(11):
  if N<=B[i]:
    name=[" "]*(i+1)
    if i==0:
      N=N
    else:
      N-=B[i-1]
    for j in reversed(range(i+1)):
      if j>=1:
        if N==0:
          name[i-j]="z"
        else:
          name[i-j]=a[(N-1)//A[j-1]]
        N-=N//A[j-1]*A[j-1]
      else:
        if N==0:
          name[i-j]="z"
        else:
          name[i-j]=a[N-1]
    break

print(''.join(name))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
A=np.zeros(11,dtype=int)
for i in range(11):
  A[i]=(26**(i+1))
B=np.cumsum(A)
for i in range(11):
  if N<=B[i]:
    name=[" "]*(i+1)
    if i==0:
      N=N
    else:
      N-B[i-1]
    for j in reversed(range(i+1)):
      if j>=1:
        if N==0:
          name[i-j]="z"
        else:
          name[i-j]=a[(N-1)//A[j-1]-1]
        N-=N//A[j-1]*A[j-1]
      else:
        if N==0:
          name[i-j]="z"
        else:
          name[i-j]=a[N-1]
    break

print(''.join(name))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
A=np.zeros(11,dtype=int)
for i in range(11):
  A[i]=(26**(i+1))
B=np.cumsum(A)
for i in range(11):
  if N<=B[i]:
    name=[" "]*(i+1)
    if i==0:
      N=N
    else:
      N-B[i-1]
    for j in reversed(range(i+1)):
      if j>=1:
        name[i-j]=a[N//A[j-1]-1]
        N-=N//A[j-1]*A[j-1]
      else:
        name[i-j]=a[N-1]
    break

print(''.join(name))
Problem p02659 (python)

Fixed submission:
A,B=input().split()
A=int(A)
B=int(B[0])*100+int(B[2:4])
C=A*B
if len(str(C))<3:
  print(0)
else:
  print(int(str(C)[0:len(str(C))-2]))

Buggy submission (verdict: Runtime Error):
import math
import decimal
A,B=input().split()
print(Decimal(A)*Decimal(B)//1)
Problem p02598 (python)

Fixed submission:
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while math.ceil(a) != math.ceil(b):
    c = (a+b)/2
    times = []
    for i in logs:
        times.append(math.floor(i/c))
    if sum(times) > K:
        a = c
    else:
        b = c
    if b - a < 0.001:
        count +=1
    if count >20:
        flg+=1
        break
if flg == 0:         
    print(math.ceil(b))
else:
    a = math.ceil(a)
    times = []
    for j in logs:
        times.append(math.floor(i/a))
    if sum(times) > K:
        print(math.ceil(b))   
    else:
        print(math.ceil(a))

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while math.ceil(a) != math.ceil(b):
    c = (a+b)//2
    times = []
    for i in logs:
        times.append(math.floor(i/c))
    if sum(times) > K:
        a = c
    else:
        b = c

print(math.ceil(b))

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
while math.ceil(a) != math.ceil(b):
    c = (a+b)/2
    times = []
    for i in logs:
        times.append(math.floor(i/c))
    if sum(times) > K:
        a = (a+b)/2
    else:
        b = (a+b)/2
        k = len(b_memo)
    b_memo.add(b)
    if len(b_memo) == k:
        count +=1
    if count>50:
        break        
print(math.ceil(b))
Problem p02623 (python)

Fixed submission:
import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cum = [0]
B_cum = [0]
A_cum[0] = A[0]
for j in range(len(A)-1):
    A_cum.append(A_cum[j]+ A[j+1])
B_cum[0] = B[0]
for l in range(len(B)-1):
    B_cum.append(B_cum[l] + B[l+1])
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    b = bisect.bisect(B_cum,K-k)
    check = i+b+1
    if check>ans:
        ans = check
check = bisect.bisect(B_cum,K)
if check>ans:
    ans = check    
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    print(B_check)
    while b - a != 0:
        c = int(round((a+b)/2))
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    print(B_check)
    while b - a != 0:
        c = int(round((a+b)/2))
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_array = np.array(A)
B_array = np.array(B)
A_cum = np.cumsum(A_array)
B_cum = np.cumsum(B_array)
for i in range(len(A_cum)):
    k = A_cum[i]
    if k >K:
        break
    a = 0
    b = len(B_cum)-1
    print(B_check)
    while b - a != 0:
        c = round((a+b)/2)
        if B_check[c] < 0:
            b = c
        else:
            a = c
        if b-a == 1:
            if B_check[b] < 0:
                b = a
            else:
                a = b
    check = i+b+2
    if check>ans:
        ans = check
print(ans)
Problem p02781 (python)

Fixed submission:
N = int(input())
K = int(input())

L = list(map(int, list(str(N))))
M = len(L)
DP = [[[0] * 2 for _ in range(K + 1)] for _ in range(M)]

DP[0][1] = [L[0] - 1, 1]
DP[0][0][0] = 1

for i in range(1, M):
  DP[i][0][0] = DP[i - 1][0][0]
  for j in range(1, K + 1):
    if L[i] != 0:
      DP[i][j][0] = DP[i - 1][j][0]
      DP[i][j][0] += DP[i - 1][j][1]
      DP[i][j][0] += DP[i - 1][j - 1][0] * 9
      DP[i][j][0] += DP[i - 1][j - 1][1] * (L[i] - 1)
      DP[i][j][1] = DP[i - 1][j - 1][1]
    else:
      DP[i][j][0] = DP[i - 1][j][0]
      DP[i][j][0] += DP[i - 1][j - 1][0] * 9
      DP[i][j][1] = DP[i - 1][j][1]

ans = DP[-1][-1][0] + DP[-1][-1][1]
ans = max(0, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

L = list(map(int, list(str(N))))

M = len(L)
if M < K:
  x = 1 / 0
DP = [[[0] * 2 for _ in range(K + 1)] for _ in range(M)]

DP[0][1] = [L[0] - 1, 1]
DP[0][0][0] = 1

for i in range(1, M):
  DP[i][0][0] = DP[i - 1][0][0]
  for j in range(1, K + 1):
    DP[i][j][0] = DP[i - 1][j][0]
    DP[i][j][0] += DP[i - 1][j - 1][0] * 9
    DP[i][j][0] += DP[i - 1][j - 1][1] * (L[i] - 1)
    DP[i][j][0] += DP[i - 1][j][1] 
    DP[i][j][1] = DP[i - 1][j - 1][1]

ans = DP[-1][-1][0] + DP[-1][-1][1]
ans = max(0, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

L = list(map(int, list(str(N))))

M = len(L)
if L < M:
  x = 1 / 0
DP = [[[0] * 2 for _ in range(K + 1)] for _ in range(M)]

DP[0][1] = [L[0] - 1, 1]
DP[0][0][0] = 1

for i in range(1, M):
  DP[i][0][0] = DP[i - 1][0][0]
  for j in range(1, K + 1):
    DP[i][j][0] = DP[i - 1][j][0]
    DP[i][j][0] += DP[i - 1][j - 1][0] * 9
    DP[i][j][0] += DP[i - 1][j - 1][1] * (L[i] - 1)
    DP[i][j][0] += DP[i - 1][j][1] 
    DP[i][j][1] = DP[i - 1][j - 1][1]

ans = DP[-1][-1][0] + DP[-1][-1][1]
ans = max(0, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

L = list(map(int, list(str(N))))
if L < K:
  x = 1 / 0
M = len(L)
DP = [[[0] * 2 for _ in range(K + 1)] for _ in range(M)]

DP[0][1] = [L[0] - 1, 1]
DP[0][0][0] = 1

for i in range(1, M):
  DP[i][0][0] = DP[i - 1][0][0]
  for j in range(1, K + 1):
    DP[i][j][0] = DP[i - 1][j][0]
    DP[i][j][0] += DP[i - 1][j - 1][0] * 9
    DP[i][j][0] += DP[i - 1][j - 1][1] * (L[i] - 1)
    DP[i][j][0] += DP[i - 1][j][1] 
    DP[i][j][1] = DP[i - 1][j - 1][1]

ans = DP[-1][-1][0] + DP[-1][-1][1]
ans = max(0, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())

L = list(map(int, list(str(N))))
if L < N:
  x = 1 / 0
M = len(L)
DP = [[[0] * 2 for _ in range(K + 1)] for _ in range(M)]

DP[0][1] = [L[0] - 1, 1]
DP[0][0][0] = 1

for i in range(1, M):
  DP[i][0][0] = DP[i - 1][0][0]
  for j in range(1, K + 1):
    DP[i][j][0] = DP[i - 1][j][0]
    DP[i][j][0] += DP[i - 1][j - 1][0] * 9
    DP[i][j][0] += DP[i - 1][j - 1][1] * (L[i] - 1)
    DP[i][j][0] += DP[i - 1][j][1] 
    DP[i][j][1] = DP[i - 1][j - 1][1]

ans = DP[-1][-1][0] + DP[-1][-1][1]
ans = max(0, ans)
print(ans)