qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s,t = input().split()
    a,b = LI()
    d = {}
    d[s] = a
    d[t] = b
    u = input()
    d[u] -= 1
    print(d[s],d[t])
    return

#Solve
if __name__ == "__main__":
    solve()


Fixed code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s,t = input().split()
    a,b = LI()
    d = {}
    d[s] = a
    d[t] = b
    u = input()
    d[u] -= 1
    print(d[s],d[t])
    return

#Solve
if __name__ == "__main__":
    solve()
Buggy code:
str1, str2 = input().split()
num1, num2 = map(int,input.split())
trim = input()

if trim == str1:
	num1 = num1 - 1
else:
  	num2 = num2 - 1

print("%d %d",%(num1, num2))


Fixed code:
str1, str2 = input().split()
num1, num2 = map(int,input().split())
trim = input()
 
if trim == str1:
	num1 = num1 - 1
else:
  	num2 = num2 - 1
 
print("%d %d"  %(num1, num2))
Buggy code:
S, T = input().split()
s_i, t_i = map(int, input().split())
U = input()

if U == S:
    print(str(s_i - 1) + " " + str(t_i))
else
    print(str(s_i) + " " + str(t_i - 1))

Fixed code:
S, T = input().split()
s_i, t_i = map(int, input().split())
U = input()

if U == S:
    print(str(s_i - 1) + " " + str(t_i))
else:
    print(str(s_i) + " " + str(t_i - 1))
Buggy code:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=str(input())

if "S"=="U":
  print(A-1,B)
else:
  print(A,B-1)

Fixed code:
S, T = map(str,input().split())
A, B = map(int,input().split())
U = str(input())

if U == S:
    A = A - 1
else:
    B = B - 1

print(A, B)
Buggy code:
S,T=input().split()
A,B=map(int,input().split())
U=input()

if "S"=="U":
  print(A-1,B)
else:
  print(A,B-1)

Fixed code:
S, T = input().split()
A, B = map(int, input().split())
U = input()

#print(S, T, A, B, U)
if S == U:
  A -= 1
else:
  B -= 1

print(A, B)
Buggy code:
S, T = input().split()
A, B = input().split()
U = input()

print(f"{int(A) - 1 if S == U else 0} {int(B) - 1 if T == U else 0}")


Fixed code:
S, T = input().split()
A, B = input().split()
U = input()

print("{} {}".format(int(A) - (1 if S == U else 0), int(B) - (1 if T == U else 0)))
Buggy code:
S, T, U = map(input().split())
A, B = map(int,input().split)

if S == U:
    print(S-1 " " T)
else:
    print(S " " T-1)


Fixed code:
S, T = input().split()
A, B = map(int,input().split())
U = input()

if (U == S):
    print(A - 1, B)
else:
    print(A, B - 1)
Buggy code:
S, T = map(str, input().split())
A, B = map(int, input().split())
U = input(str)
if S == U:
  print(A-1),
  print(B),
else:
  print(A),
  print(B-1),

Fixed code:
S,T = map(str,input().split())

A,B = map(int,input().split())

U = input()

if U == S:
  Sans = int(A) - 1
  print(Sans,B)
else:
  Tans = int(B) - 1
  print(A,Tans)
Buggy code:
s,t=input().split()
a,b=map(int,input().split())
u=input()
if u==s:
  print(str(a-1)+ ''+str(b))
else:
  print(str(a)+ ''+str(b-1)) 

Fixed code:
s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()

if u == s:
	print(a-1, b)
else:
	print(a, b-1)
Buggy code:
S, T = input().split()
r, b = map(int, input().split())
N = input()

if S == N:
  r -= 1
elif T == N:
  b -= 1
  
 print(r, b)

Fixed code:
S,  T = input().split()
r, b = map(int, input().split())
N = input()
 
if S == N:
  r -= 1
elif T == N:
  b -= 1
  
 
print(r, b)
Buggy code:
color=input().split()
x,y=map(int,input().split())
color2=input()

if color2==color[0]:
    print(x-1)
else:
    print(y-1)

Fixed code:
color=input().split()
x,y=map(int,input().split())
color2=input()

if color2==color[0]:
    print(x-1,y)
else:
    print(x,y-1)
Buggy code:
s,t = input().split()
a,b = map(int, input().split())
u = input()

if s == u or t == u:
  print(a+b-1)
else:
  print(a+b)

Fixed code:
s,t = input().split()
a,b = map(int,input().split())
u = input()

if(s == u):
  a -=1
else:
  b -=1
print(a,b)
Buggy code:
s,t = input().split()
a,b = map(int,input().split())
u = input()
if s == u:
  print(a-1,b)
if t == u:
  print(a,b-1)
else:
  print(a,b)

Fixed code:
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
if s == u:
  print(a-1, b)
else:
  print(a, b-1)
Buggy code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

import numpy as np
def main():
    S,T = input().split()
    A,B = MAP()
    U = INT()

    if S == U:
        print(A-1,B)
    else:
        print(A,B-1)

    return

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    S,T = input().split()
    A,B = MAP()
    U = input()

    if S == U:
        print(A-1,B)
    else:
        print(A,B-1)

    return

if __name__ == '__main__':
    main()
Buggy code:
S, T = input().split()
A, B = [int(n) for n in input().split()]
ans = {S:A, T:B}
U = input()
ans[U] -= 1
print([i for i in ans.values()])


Fixed code:
S, T = input().split()
A, B = [int(n) for n in input().split()]
ans = {S:A, T:B}
U = input()
ans[U] -= 1
print(ans[S], ans[T])
Buggy code:
S,T=input().split()
a,b=map(int,input().split())
U=input()
print(a-1,b) if S==U else (a,b-1)

Fixed code:
S,T=input().split()
a,b=map(int,input().split())
U=input()
print(a-1,b) if S==U else print(a,b-1)
Buggy code:
n,t = input().split()
a,b = map(int,input().split())
print(a)
u = input()
if u == n:
    print(a-1)
else:
    print(b-1)

Fixed code:
n,t = input().split()
a,b = map(int,input().split())
u = input()
if u == n:
    print(a-1,b)
else:
    print(a,b-1)
Buggy code:
s,t=input().split()
a,b=map(int,input().split())
u=str(input())

if s==u:
  print(a-1 b)
else:
  print(a b-1)

Fixed code:
s,t=input().split()
a,b=map(int,input().split())
u=input()
print(a-1,b) if u==s else print(a,b-1)
Buggy code:
s,t = input().split()
sn,tn = map(int,input().split())
u  = input()

if s == u:
	print((sn-1) ' '+ (tn))
else:
	print(sn + '' + (tn-1))

Fixed code:
s,t = input().split()
sn,tn = map(int,input().split())
u  = input()

if s == u:
    print(str(sn-1) + ' '+ str(tn))
else:
    print(str(sn) + ' ' + str(tn-1))
Buggy code:
moji = list(map(str,input().split()))
kazu = list(map(int,input().split()))
U = input()
print(kazu[moji.index(U)] -1)

Fixed code:
moji = list(map(str,input().split()))
kazu = list(map(int,input().split()))
U = input()
kazu[moji.index(U)] -= 1
print(kazu[0],kazu[1])
Buggy code:
s,t=map(str,input().split(" "))
a,b=map(int,input().split(" "))
u=str(input())

if s==u:
  print(a-1" "b)
else:
  print(a" "b-1)

Fixed code:
s, t = input().split(" ")
a, b = map(int, input().split(" "))
u = input()

if s == u:
    print(a-1, b)
elif t == u:
    print(a, b-1)
else:
    print(a, b)
Buggy code:
s, t = input().split()
a, b = map(int, input().split())
u = input()

if s==u:
	print((a-1)+' '+b)
elif t==u:
	print(a+' '+(b-1))

Fixed code:
s, t = input().split()
a, b = map(int, input().split())
u = input()

if s==u:
	print(a-1, b)
elif t==u:
	print(a, b-1)
Buggy code:
S,T = input().split()
A,B = input().split()
U = input()

if U = S:
  print(A-1)
else:
  print(B-1)


Fixed code:
S,T = input().split()
A,B = input().split()
U = input()

if U == S:
  print(int(A)-1, B)
else:
  print(A, int(B)-1)
Buggy code:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=str(input())
if S==T:
  print(A-1,B)
else:
  print(A,B-1)


Fixed code:
S, T = input().split()
A, B = map(int, input().split())
U = input()

if U == S:
    print(A - 1, B)
else:
    print(A, B - 1)
Buggy code:
def main():
    s = input().split()
    n, m = list(map(int, input().split()))
    d = input()
    #print(s)
    if s[0] == d:
        print(n - 1, m)
    else:
        print(n, m - 1)


if __name__

Fixed code:
def main():
    s = input().split()
    n, m = list(map(int, input().split()))
    d = input()
    #print(s)
    if s[0] == d:
        print(n - 1, m)
    else:
        print(n, m - 1)


if __name__ == "__main__":
    main()
Buggy code:
S,T=map(int,input().split())
A,B=map(int,input().split())
U=int(input())

if S==U:
    A-=1
else:
    B-=1

print(str(A)+" "+str(B))


Fixed code:
S,T=map(str,input().split())
A,B=map(int,input().split())
U=input()
if S==U:
    A-=1
else:
    B-=1
print(A,B)
Buggy code:
S, T = input().split()
A, B = (int(x) for x in input().split())
U = input()
print(A - int(S==U), B - int(T==U) if S == U or T == U)
  

Fixed code:
S, T = input().split()
A, B = (int(x) for x in input().split())
U = input()
if S == U or T == U:
  print(A - int(S==U), B - int(T==U))
Buggy code:
s t = map(str, input().split())
a b = map(int, input().split())
u = input()
if s == u:
    print(a-1, b)
else:
    print(a, b-1)

Fixed code:
s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
if s == u:
    print(a-1, b)
else:
    print(a, b-1)
Buggy code:
s, t= input().split(' ')
a, b = map(int,input().split(' '))
u = input()
print(a-1) if u == s else print(b-1)

Fixed code:
s, t= input().split(' ')
a, b = map(int,input().split(' '))
u = input()
print(a-1, b) if u == s else print(a, b-1)
Buggy code:
s,t = map(str,input().split())
a,b = map(int,input().split())
u = int(input())
if s == u:
  print(a-1,b)
else:
  print(a,b-1)

Fixed code:


s, t = input().split()

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

u = input()


if u == s:
    a -= 1
if u == t:
    b -= 1

print(a, b)
Buggy code:
S,T = input().split()
A,B = map(int,input().split())
U = input()

if S == U:
  print({},{}).format(A-1,B)
else:
  print({},{}).format(A,B-1)

Fixed code:
S,T = input().split()
A,B = map(int,input().split())
U = input()
 
if S == U :
    print("{} {}".format(A-1,B))
else :
    print("{} {}".format(A,B-1))
Buggy code:
import functiontool
N = int(input())
K = int(input())

@functools.lru_cache(user_function)
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

Fixed code:
import functools
N = int(input())
K = int(input())

@functools.lru_cache(None)
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))
Buggy code:

N = int(input())
K = int(input())

@lru_cache
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

Fixed code:
import functools
N = int(input())
K = int(input())

@functools.lru_cache()
def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))
Buggy code:
N = int(input())
K = int(input())


def func(num,counter):
    remain = num%10
    quotient = num//10
    print(num,counter)
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))

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


def func(num,counter):
    remain = num%10
    quotient = num//10
    
    
    if counter == 0:
        return 1
    
    if num<10:
        if counter ==1:
            return num
        else:
            return 0

    return func(quotient,counter-1)*remain + func(quotient-1,counter-1)*(9-remain) + func(quotient,counter)

print(func(N,K))
Buggy code:
def comb(n, k):
  c = 1
  for i in range(k):
    c *= n-i
    c //= i+1
  return c

n = [int(i) for i in input()]
l = len(n)
k = int(input())
if l == k:
  count = 1
else:
  count = 0
for i in range(l):
  print(i, count)
  # n[:i] 0 {1..9}*k 0*(l-i-1-k)
  count += 9 ** k * comb(l-i-1, k)
  # n[:i] {1..(n[i]-1)} {1..9}*(k-1) 0*(l-i-1-k)
  if k >= 1:
    count += 9 ** (k-1) * comb(l-i-1, k-1) * (n[i]-1)
  else:
    break
  # Next is n[:i+1] {1..9}*(k-1) 0*(l-i-k)
  k -= 1
print(count)

Fixed code:
def comb(n, k):
  c = 1
  for i in range(k):
    c *= n-i
    c //= i+1
  return c

n = [int(i) for i in input()]
l = len(n)
k = int(input())
count = 0
for i in range(l):
  if n[i] > 0:
    # n[:i] 0 {1..9}*k 0*(l-i-1-k)
    count += 9 ** k * comb(l-i-1, k)
    # n[:i] {1..(n[i]-1)} {1..9}*(k-1) 0*(l-i-1-k)
    if k >= 1:
      count += 9 ** (k-1) * comb(l-i-1, k-1) * (n[i]-1)
    else:
      break
    # Next is n[:i+1] {1..9}*(k-1) 0*(l-i-k)
    k -= 1
  if i == l-1 and k == 0:
    count += 1
print(count)
Buggy code:
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    n = list(input())
    k = get_int()
    ln = len(n)
    ans = 0
    def solve(nz, ind, locked = False):
        if nz == 0: return 1
        if ind>=ln: return 0
        num = int(n[ind])
        ans = 0
        for index in range(ind,ln):
            if locked and ind==index:
                if num==0: return 0
                for i in range(index+1, ln):
                    if int(n[i])>0:
                        ans += solve(nz-1, i, True)
                        break
                ans += solve(nz-1, index+1)*(num-1)
            else: ans += solve(nz-1, index+1)*9
        #print(nz, ind, locked, ans)
        return ans

    ans = solve(k,0, True)
    print(ans)


''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


Fixed code:
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    n = list(input())
    k = get_int()
    ln = len(n)
    ans = 0
    def solve(nz, ind, locked = False):
        if nz == 0: return 1
        if ind>=ln: return 0
        num = int(n[ind])
        ans = 0
        for index in range(ind,ln):
            if locked and ind==index:
                if nz==1: ans += 1
                else:
                    for i in range(index+1, ln):
                        if int(n[i])>0:
                            ans += solve(nz-1, i, True)
                            break
                ans += solve(nz-1, index+1)*(num-1)
            else: ans += solve(nz-1, index+1)*9
            #print(index, ans)
        #print(nz, ind, locked, ans)
        return ans

    ans = solve(k,0, True)
    print(ans)


''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')
Buggy code:
import sys
readline = sys.stdin.readline

N = readline().strip()
K = int(readline())

MM = [9, 81, 9 ** 3]

def comb(n, k):
    a = 1
    for i in range(k):
        a *= n - i
    
    for i in range(k):
        a = a // (i + 1)
    
    return a

def xxx(N, K):
    L = len(N)
    if L <= K - 1:
        return 0
    
    if K == 0:
        return 1
    
    a = comb(L - 1, K) * MM[K - 1]

    b = int(N[0]) - 1
    a += b * comb(L - 1, K - 1) * MM[K - 2] if K >= 2 else b
    
    a += xxx(N[1:], K - 1)
    print(N, K, a)
    return a

print(xxx(N, K))

Fixed code:
import sys
readline = sys.stdin.readline

N = readline().strip()
K = int(readline())

MM = [9, 81, 9 ** 3]

def comb(n, k):
    a = 1
    for i in range(k):
        a *= n - i
    
    for i in range(k):
        a = a // (i + 1)
    
    return a

def xxx(N, K):
    L = len(N)
    if L <= K - 1:
        return 0
    
    if K == 0:
        return 1
    
    a = comb(L - 1, K) * MM[K - 1]

    b = int(N[0]) - 1
    a += b * comb(L - 1, K - 1) * MM[K - 2] if K >= 2 else b
    
    _i = L
    for i in range(1, L):
        if N[i] != '0':
            _i = i
            break

    if _i < L:
        a += xxx(N[_i:], K - 1)
    elif K == 1:
        a += 1
    return a

print(xxx(N, K))
Buggy code:
import sys 
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N = int(readline())
K = int(readline())
@lru_cache(None)
def f(N,K):
    if K == -1:
        return 0
    if N < 10:
        if K == 0:
            return 1
        elif K == 1:
            return N
        else:
            return 0
    ans = 0
    q, mod = divmod(N, 10)
    ans += f(q,K) + mod * f(q,K-1) + (9-mod) * f(q-1,K-1) 
    return ans
print(f(N,K))

Fixed code:
import sys 
from functools import lru_cache
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N = int(readline())
K = int(readline())
@lru_cache(None)
def f(N,K):
    if K == -1:
        return 0
    if N < 10:
        if K == 0:
            return 1
        elif K == 1:
            return N
        else:
            return 0
    ans = 0
    q, mod = divmod(N, 10)
    ans += f(q,K) + mod * f(q,K-1) + (9-mod) * f(q-1,K-1) 
    return ans
print(f(N,K))
Buggy code:
    r = 1
    for i in range(a):
        r *= i+1
    return r

def combinations(a, b):
    if a>=0 and b>=0 and a >= b:
        return pow(9, b) * factorial(a) // factorial(b) // factorial(a-b)
    else:
        return 0

def count(m, a, b):
    # return the count of numbers in range [0, m x 10^a] with b non zero digitals
    ## the count of numbers in range [0, m x 10^a) with b non zero digitals
    r = combinations(a-1, b) + (m-1) * combinations(a-1, b-1)
    if b == 1:
        ## m x 10^a
        r += 1
    return r

N = int(input())
K = int(input())

digit = list(map(int, str(N)))
M = len(digit)

C = 0
if M >= K:
    for i in range(K):
        C += count(digit[i], M-i, K-i)

print(C)    


Fixed code:
def factorial(a):
    r = 1
    for i in range(a):
        r *= i+1
    return r

def combinations(a, b):
    if a>=0 and b>=0 and a >= b:
        return pow(9, b) * factorial(a) // factorial(b) // factorial(a-b)
    else:
        return 0

def count(m, a, b):
    # return the count of numbers in range [0, m x 10^a] with b non zero digitals
    ## the count of numbers in range [0, m x 10^a) with b non zero digitals
    r = combinations(a-1, b) + (m-1) * combinations(a-1, b-1)
    if b == 1:
        ## m x 10^a
        r += 1
    return r

def COUNT(N,K):
    digit = list(map(int, str(N)))
    M = len(digit)
    C = count(digit[0], M, K)
    N_ = N % pow(10, M-1)
    return C, N_
    

N = int(input())
K = int(input())

C = 0
while (N>0) and (K>0):
    c, N = COUNT(N, K)
    C+= c
    K-= 1

print(C)
Buggy code:
def main():
    s = [int(char) for char in input()]
    l = len(s)
    k = int(input())

    tmp = 0
    nonzero = []
    for number in s:
        if number > 0:
            tmp += 1
        nonzero.append(tmp)
    nonzero.append(0)  # let nonzero[-1] be 0

    def binomial(n, k):
        if n < k or n < 0 or k < 0:
            raise ValueError
        if k == 0:
            return 1
        if k == 1:
            return n
        if k == 2:
            return n * (n-1) // 2
        if k == 3:
            return n * (n-1) * (n-2) // 6
        raise ValueError

    def dp(i, _cache={-1: 0}):
        if i in _cache:
            return _cache[i]
        if nonzero[i-1] > k or s[i] == 0:
            result = dp(i-1)
            _cache[i] = result
            return result
        if nonzero[i-1] == k:
            result = dp(i-1) + 1
            _cache[i] = result
            return result
        result = (
            dp(i-1) +
            (s[i] - 1) * binomial(l - 1 - i, k - nonzero[i-1] - 1) *
            9 ** (k - nonzero[i-1] - 1) +
            binomial(l - 1 - i, k - nonzero[i-1]) *
            9 ** (k - nonzero[i-1])
        )
        _cache[i] = result
        return result
    
    print(dp(l-1) + (nonzero[l-1] == k))


main()


Fixed code:
def main():
    s = [int(char) for char in input()]
    l = len(s)
    k = int(input())

    tmp = 0
    nonzero = []
    for number in s:
        if number > 0:
            tmp += 1
        nonzero.append(tmp)
    nonzero.append(0)  # let nonzero[-1] be 0

    def binomial(n, k):
        if n < k or n < 0 or k < 0:
            return 0
        if k == 0:
            return 1
        if k == 1:
            return n
        if k == 2:
            return n * (n-1) // 2
        if k == 3:
            return n * (n-1) * (n-2) // 6
        raise ValueError

    def dp(i, _cache={-1: 0}):
        if i in _cache:
            return _cache[i]
        if nonzero[i-1] > k or s[i] == 0:
            result = dp(i-1)
            _cache[i] = result
            return result
        if nonzero[i-1] == k:
            result = dp(i-1) + 1
            _cache[i] = result
            return result
        result = (
            dp(i-1) +
            (s[i] - 1) * binomial(l - 1 - i, k - nonzero[i-1] - 1) *
            9 ** (k - nonzero[i-1] - 1) +
            binomial(l - 1 - i, k - nonzero[i-1]) *
            9 ** (k - nonzero[i-1])
        )
        _cache[i] = result
        return result
    
    print(dp(l-1) + (nonzero[l-1] == k))


main()