Problem:


Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300



Sample input:
100
1


Sample output:
19

Submission status: Time Limit Exceeded

Solution code:
#E 復習
N = int(input())
K = int(input())

def f(n, K):
    if n <= 10:
        if K == 0:
            return 1
        if K == 1:
            return n
        return 0
    div_n = n//10
    mod_n = n%10
    ans = 0
    if K >= 1:
        ans += f(div_n, K-1) * mod_n
        ans += f(div_n-1, K-1) * (9 - mod_n)
    ans += f(div_n, K)
    return ans

print(f(N, K))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
c = 0

for x in range(n + 1):
    l = list(str(x))
    if len(l) - l.count("0") == k:
        c += 1

print(c)

Submission status: Time Limit Exceeded

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

count = 0
for n in range(N + 1):
    n = str(n)
    flag = len(n) - n.count('0')
    if flag == K:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def rec(digit, flag, k):
    limit = int(N[digit])
    if k > K:
        return 0
    if digit == len(N) - 1:
        if k == K:
            return 1
        elif k == K - 1:
            return limit if flag else 9
        else:
            return 0
    if flag:
        if limit == 0:
            return rec(digit + 1, 1, k)
        else:
            return rec(digit + 1, 0, k + 1) * (limit - 1) + rec(digit + 1, 1, k + 1) + rec(digit + 1, 0, k)
    else:
        return rec(digit + 1, 0, k + 1) * 9 + rec(digit + 1, 0, k)

N = input()
K = int(input())
print(rec(0, 1, 0))

Submission status: Time Limit Exceeded

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

def CountNotZero(n):
    NotZero=0
    while n>0:
        if (n%10)!=0:
            NotZero+=1
        n=int(n/10)  
    return NotZero

def main(n,k):
    answer=0
    while n>0: 
        if CountNotZero(n)==k:
            answer+=1
        n-=1
    return answer

print(main(N,K))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
count = 0
iterator = ''

for i in range(n):
   iterator = str(i+1)
   num = iterator.replace('0', '')
   if len(num) == k:
       count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
sys.setrecursionlimit(1000000000)
from functools import lru_cache

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

# f(N,K)が回答になるようにする。
@lru_cache(maxsize=10009900)
def f(n, k):
    # 終了条件
    if n < 10:
        if k==0:
            return 1
        elif k==1:
            return n
        return 0
    
    ret = 0
    z = int(math.log10(n))
    keta = 10**z
    base = n % keta

    # 0のとき
    ret += f(keta-1, k)
    # 1..9のとき
    for i in range(1,10):
        if keta * (i+1) <= n:
            ret += f(keta-1, k-1)
        elif keta * i <= n:
            ret += f(base, k-1)

    return ret

print(f(N,K))

Submission status: Time Limit Exceeded

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

ret = 0
for n in range(1,N+1):
  b = [1 if int(c) > 0 else 0 for c in str(n)]
  if sum(b) == K:
    ret += 1

    
print(ret)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
c,res=0,0
for i in range(1,n+1):
	for j in str(i):
		if j!="0":
			c+=1
	if c==k:
		res+=1
	c=0
print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
def cal(n,k):
  if n<10:
    if k==0: return 1
    if k==1: return n
    return 0
  q,r=divmod(n,10)
  ret=0
  if k>=1:
    ret+=cal(q,k-1)*r
    ret+=cal(q-1,k-1)*(9-r)
  ret+=cal(q,k)
  return ret

print(cal(n,k))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
cnt=0
for i in range(1,n+1):
  temp=str(i)
  # ll=len(temp)
  if(temp.count('0')==(len(temp)-k)):
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    K = int(input())
    start = 1
    if K == 2:
        start = 11
    elif K==3:
        start=111
    count = 0
    for i in range(start,N+1):
        tmp = str(i)
        if (len(tmp) - tmp.count('0')) ==K:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
res = 0

for i in range(n + 1):
    point = list(filter(lambda x: x != 0 ,(list(map(int, str(i))))))
    #point = [m for m in point if m != 0]
    #print(point)
    if len(point) == k:
        res += 1
        
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
res = 0

for i in range(n + 1):
    point = (list(map(int, str(i))))
    point = [m for m in point if m != 0]
    #print(point)
    if len(point) == k:
        res += 1
        
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
total = 0
for i in range(1,n+1):
    j = i
    t = 0
    while j!=0:
        if j%10 != 0:
            t+=1
        j//=10
    if t == k:
        total+=1
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

def is_nk(n, k):
  nn = list(filter(lambda x: x!='0', list(str(n))))
  if len(nn)==k:
    return True
  return False

num=0
for i in range(n+1):
  if is_nk(i, k):
    num+=1
print(num)

Submission status: Time Limit Exceeded

Solution code:
import itertools 
n = int(input())
k = int(input())
digit = len(str(n))
result = 0

# def factorial(p):
#     re = 1
#     for i in range(1, p+1):
#         re *= i
#     return re
# def choose(a, b):
#     return int(factorial(a)/(factorial(b)*factorial(a-b)))
cb = int("9"*k)
# result += choose(cb, k) * choose(5, k)

seq = [1]*(k) + [0]*(digit-k)
realpositionlist = list(set(list(itertools.permutations(seq))))
#最高桁以外
resultnumberlist = []
for l2 in realpositionlist:
    if k == 1:
        for a in range(1,10):
            resultnumberstring = "".join(map(str,l2)).replace("1", str(a), 1) 
            resultnumber =int(resultnumberstring)
            resultnumberlist.append(resultnumber)
    elif k == 2:
        for a in range(1, 10):
            for b in range(1, 10):
                resultnumberstring = "".join(map(str,l2)).replace("1", str(b), 2)
                resultnumberstring = resultnumberstring.replace(str(b), str(a),1)
                resultnumber =int(resultnumberstring)
                resultnumberlist.append(resultnumber)
    elif k == 3:
        for a in range(1, 10):
            for b in range(1, 10):
                for c in range(1, 10):
                    resultnumberstring = "".join(map(str,l2)).replace("1", str(c), 3)
                    resultnumberstring = resultnumberstring.replace(str(c), str(b),2)
                    resultnumberstring = resultnumberstring.replace(str(b), str(a),1)
                    resultnumber =int(resultnumberstring)
                    resultnumberlist.append(resultnumber)

for b in resultnumberlist:
    if b <= n:
        result += 1

print(result)

Submission status: Time Limit Exceeded

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

total = 0
for num in range(1, N+1):
    if len(str(num)) - str(num).count('0') == K:
        total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
mx = int(input())
ct = int(input())
c = 0
for i in range(mx):
  if len(str(i + 1)) - [c for c in str(i + 1)].count("0") == ct:
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())


def f(n, k):
    assert n >= 0 #例外処理
    if n < 10:
        if k == 0:
            return 1 #0しかない数 = 0
        elif k == 1:
            return n #k = 1ならn個分存在している
        return 0 #k >= 2のときは、0を返す
    
    q, r = divmod(n, 10)
    res = 0
    
    if k >= 1:
        #1の位が0でないとき
        res += f(q, k-1) * r
        res += f(q-1, k-1) * (9 - r)
    #１の位が0
    res += f(q, k)
    return res

print(f(n, k))

Submission status: Time Limit Exceeded

Solution code:
# reference https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2019-02-09abc-154
from functools import lru_cache

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


# @lru_cache(None)
def F(N, K):
    # print("NK", N, K)
    """N以下で0でないものがちょうどK個。0を含める"""
    # assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        if K == 1:
            return N
        return 0  # 求める数字は作れない
    q, r = divmod(N, 10)
    # print("qr", q, r)
    ret = 0
    if K >= 1:  # 1 の位が nonzero (1 の位で 0 でない数字 を消費するので、第 2 引数は K - 1)
        ret += F(q, K-1) * r  # smaller than 1 の位
        ret += F(q-1, K-1) * (9-r)  # bigger than 1 の位
    ret += F(q, K)  # 1の位が zero (1 の位で 0 でない数字 を消費していないので、第 2 引数は K)
    return ret


print(F(N, K))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1,N+1) :
    list_i = [i for i in str(i) if i != "0"]
    if len(list_i) == K :
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

def dp(N, K):
  if N < 10:
    if K == 0:
      return 1
    if K == 1:
      return N
    return 0
  q, r = divmod(N, 10)
  ret = 0
  if K >= 1: # 下一桁が0でないときはKを1消化
    ret += dp(q, K-1) * r # 下一桁がr以下の時
    ret += dp(q-1, K-1) * (9-r) # 下一桁がrより上の時はq-1であれば成立
  ret += dp(q, K) # 下一桁が0のとき
  return ret

print(dp(N, K))

Submission status: Time Limit Exceeded

Solution code:
n=int(input(""))

no=int(input(""))
def has0(x):
    out=int()
    out=0
    while (x != 0):


        if (x % 10 != 0):
            out=out+1

        x = x // 10

    return out


def getCount(n):
    count = 0

    out = int()
    out = 0
    for i in range(1, n + 1):
        count = has0(i)
        if count == no:
            out=out + 1

    return out


print( getCount(n))

Submission status: Time Limit Exceeded

Solution code:
x = int(input(""))
n = int(input(""))
out = int()


def count_zero(temp):
    temp=int(temp)
    if temp != 0:
        return 1
    else:
        return 0


def count(temp):
    cout = int()
    for i in temp:
        cout = cout + count_zero(i)

    return cout

out=0
for i in range(1, x+1):
    temp = str(i)

    if count(temp) == n:
        out=out+1
print(out)

Submission status: Time Limit Exceeded

Solution code:
s=input();n=len(s)
def f(i,t,k):
 if k>n-i:return 0
 a=max(t,int(s[i]));i+=1;z=f(i,t,k)
 if a:
  if k==1:z=a+(n-i)*9
  else:z=f(i,9,k)+(a-1)*f(i,9,k-1)+f(i,t,k-1)
 return z
print(f(0,0,int(input())))

Submission status: Time Limit Exceeded

Solution code:
s=input();n=len(s)
def f(i,t,k):
 if k>n-i:return 0
 if k==0:return 1
 a=max(t,int(s[i]));i+=1;z=f(i,t,k)
 if a:z=f(i,9,k)+(a-1)*f(i,9,k-1)+f(i,t,k-1)
 return z
print(f(0,0,int(input())))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
count = 0
for i in range(1,n+1):
    if(str(i).count('0')==len(str(i))-k):
        count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
count = 0
for i in range(n+1):
    if(str(i).count('0')==len(str(i))-k):
        count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
K = int(input())
def func(N, K):
    return sum([int((len(str(val))-str(val).count('0')) == K) for val in range(N+1)])
print(func(N,K))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import lru_cache

N, K = map(int,read().split())

def F(N, K):
    """N以下で0でないものがちょうどK個。0を含める"""
    assert N >= 0
    if N < 10:
        if K == 0:
            return 1
        if K == 1:
            return N
        return 0
    q,r = divmod(N,10)
    ret = 0
    if K >= 1:
        # 1の位が nonzero
        ret += F(q, K-1) * r
        ret += F(q-1, K-1) * (9-r)
    # 1の位が zero
    ret += F(q, K)
    return ret

# F(100, 1), F(25, 2), F(314159, 2)

print(F(N, K))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
a = [i for i in range(1, n + 1) if len(str(i).replace("0", "")) == k]
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
a = 0
for i in range(1, n + 1):
  if len(str(i).replace("0", "")) == k:
    a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

num_list = []

c = 0

for i in range(n):
    temp = list(str(i + 1))
    num_0 = temp.count("0")
    non_0 = len(temp) - num_0
    if non_0 == k:
        c = c + 1

        
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

num_list = []

c = 0

for i in range(n):
    num_list.append(str(i+1))



for j in range(n):
    temp = list(num_list[j])
    num_0 = temp.count("0")
    non_0 = len(temp) - num_0
    if non_0 == k:
        c = c + 1
        
print(c)

Submission status: Time Limit Exceeded

Solution code:

import itertools
import sys
import numpy as np
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**9)


def solve(N,K):
    # print(N,K)
    if N <= 10:
        if K == 0:
            return 1
        elif K == 1:
            return N
        else:
            return 0

    if K < 0 or len(str(N)) < K:
        return 0

    ans = 0
    m, last = divmod(N,10)
    ans += solve(m,K-1) * last + solve(m-1,K-1) * (9 - last) + solve(m,K)

    return ans


def main():
    N,K = map(int,[input(),input()])
    
    print(solve(N,K))

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
N = input()
L = len(N)
K = int(input())


def main(d, k):
    if d == L:
        if k == 0:
            return 1
        else:
            return 0
    if N[d] == "0":
        return main(d + 1, k)
    if (L - d) < k:
        return 0
    return main1(d+1, k)+main1(d+1, k-1)*(int(N[d])-1)+main(d+1, k-1)


def main1(d, k):
    if k == 0:
        return 1
    if d == L:
        return 0
    return main1(d+1, k-1)*9+main1(d+1, k)


print(main(0, K))

Submission status: Time Limit Exceeded

Solution code:
def keta(n,k):
    s=str(n)
    l=len(s)-1
    if k==1:
        a=9*l
    elif k==2:
        a=81*l*(l-1)/2
    elif k==3:
        a=729*l*(l-1)*(l-2)/6
    
    i=10**l
    b=n-i+1
    for j in range(b):
        n=str(i).count('0')
        g=l-n+1
        i+=1
        if k == g:
            a+=1
    a=int(a)
    return a
N=int(input())
K=int(input())
print(keta(N,K))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = int(input())
out = 0
for i in range(a):
    s_n = str(i + 1)
    out = out + 1 if (len(s_n) - s_n.count('0')) == b else out

print(out)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
s=len(list(str(n)))
if k==1:
    ans=(s-1)*9
    for i in range(9):
        if n>=(10**(s-1))*(i+1):
            ans+=1
elif k==2:
    ans=9*9*(s-1)*(s-2)//2
    for i in range(9):
        for j in range(s-1):
            for p in range(9):
                if n>=(10**(s-1))*(i+1)+(10**j)*(p+1):
                    ans+=1
else:
    ans=9*81*(s-1)*(s-2)*(s-3)//6
    for i in range(9):
        for p in range(s-1):
            for q in range(p):
                for t in range(1,10):
                    for u in range(1,10):
                        if n>=(10**(s-1))*(i+1)+(10**p)*t+(10**q)*u:
                            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
s=len(list(str(n)))
if k==1:
    ans=(s-1)*9
    for i in range(9):
        if n>=(10**(s-1))*(i+1):
            ans+=1
elif k==2:
    ans=9*9*(s-1)*(s-2)//2
    for i in range(9):
        for j in range(s-1):
            for p in range(9):
                if n>=(10**(s-1))*(i+1)+(10**j)*(p+1):
                    ans+=1
else:
    ans=9*81*(s-1)*(s-2)*(s-3)//6
    for i in range(9):
        for p in range(s-1):
            for q in range(s-1):
                if p<q:
                    for t in range(1,10):
                        for u in range(1,10):
                            if n>=(10**(s-1))*(i+1)+(10**p)*t+(10**q)*u:
                                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

K = int(input())


cnt_2 = 0
for j in range(N+1):
    cnt_1 = 0
    s = [k for k in str(j)]
    l = len(s)
    for i in range(l):
        if s[i]!='0':
            cnt_1+=1
    if cnt_1==K:
        cnt_2+=1

print(cnt_2)

Submission status: Time Limit Exceeded

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

count=0
for i in range(1,N+1):
    if str(i).count('9')+str(i).count('1')+str(i).count('2')+str(i).count('3')+str(i).count('4')+str(i).count('5')+str(i).count('6')+str(i).count('7')+str(i).count('8')==K:
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
k = int(input())

c=0
for i in range(1, n+1):
        #print(i)
        si=str(i)
        if (len(si) - si.count('0')) == k:
                #print(i)
                c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
K = int(input())
ans = 0

if K == 1:
  ans += 9 * (len(str(N))-1) + int(str(N)[0])
else:
  for i in range(N):
    if len(str(i+1)) - list(str(i+1)).count('0') == K:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
K=int(input())
p=0
cnt=0
S=[]
for i in range(N+1):
  p=0
  A=str(i)
  for j in range(len(A)):
    if A[j]!="0":
      p=p+1
  if p==K:
    cnt=cnt+1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

total = 0
for i in range(1,n+1):
  s = str(i)
  cnt = 0
  for c in s:
    if c != '0':
      cnt += 1
    if cnt > k:
      break
  if cnt == k:
    total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
su = 0
m = int(input())
nonZeros = int(input())
for i in range(1,m +1):
    num = i
    currNonZeros = 0
    while(num!=0):
    	if num % 10 != 0:
   		    currNonZeros += 1
    	num = int(num/10)
    if currNonZeros == nonZeros:
    	su += 1
print(su)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
c = 0
for i in range(1, n+1):
    s = str(i)
    if '0' in s:
        num = s.count('0')
        if len(s)-num == k:
            c+=1
    else :
        if len(s) == k:
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

R = 0

for i in range(N+1):
    s = str(i)
    R += 1 if len(s) - s.count('0') == K else 0

print(R)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
count = 0
for i in range(n+1):
    arr = list(str(i))
    not0 = [j for j in arr if j != '0']
    if len(not0) == k:
        count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# E
N = int(input())
K = int(input())
import math
L = math.ceil(math.log10(N)) # 桁数

if K==1:
    print(9 * (L-1) + N//(1*10**(L-1)))
if K==2:
    if L==1:
        print(0)
    else:
        s = 0
        for i in range(2,L):
            s += 9*9*(i-1)
        # 全探索しちゃう
        for i in range(1,L):
            for mx in range(1,10):
                for lx in range(1,10):
                    if N >= (mx*10**(L-1) + lx*10**(i-1)):
                        s += 1
        print(s)
if K==3:
    if L<=2:
        print(0)
    else:
        s = 0
        for i in range(3,L):
            for j in range(2,i):
                s += 9*9*9*(j-1)
        for mx in range(1,10): # 先頭
            for bi in range(2,L): # おっきい方
                for bx in range(1,10):
                    for si in range(1,bi): # ちっさい方
                        for sx in range(1,10):
                            if N >= (mx*10**(L-1) + bx*10**(bi-1) + sx*10**(si-1)):
                                s += 1
        print(s)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    K = int(input())
    cnt = 0
    for i in range(N+1):
        s = 0
        list_i = list(str(i))
        for j in range(1,10):
            s += list_i.count(str(j))
        if s == K:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

li = [i for i in range(1, n+1, 1) if k == len([j for j in str(i) if j != '0'])]
print(len(li))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
counter = 0
kotae = 0
num = 0
num2 = 0

for i in range(n+1):
    num = i
    counter = 0
    s = str(num)
    if(len(s)<k):
        continue
    else:
        for j in range(len(s)):
            if(counter>k):
                break
            num2 = num // 10*10
            if(not num-num2==0):
                counter = counter + 1
            num = num//10
        if(counter == k):
            kotae = kotae + 1

print(kotae)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
counter = 0
for i in range(10**(k-1),n+1):
    if len(list(str(i))) - list(str(i)).count('0') == k:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
count=0
for i in range(10**(k-1),n+1):
  s=str(i)
  n=len(s)
  if k>1:
      if '0' not in s:
          #print(s)
          if n==k:
              count+=1
      else:
          if n-s.count('0')==k:
              count+=1
  else:
      if n-s.count('0')==k:
          count+=1
       
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
cnt = int(input())
res = 0
for i in range(num):
  tmp =0
  for j in str(i+1):
    if j != '0':
      tmp+=1
    if tmp > cnt:
      break
  if cnt == tmp:
    res +=1
print(res)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1,N+1):
  tmp = str(i)
  if len(str(tmp)) - tmp.count('0') == K:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

total = 0
for i in range(1,n+1):
  s = str(i)
  cnt = 0
  for c in s:
    if c == '0':
      cnt += 1
  if len(s) - cnt == k:
    total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
cnt=0

for i in range(1,n+1):
    if len(str(i))-str(i).count("0")==k:
        cnt +=1
    else:
        continue

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
K = int(input())
ans = 0

for i in range(N):
  if len(str(i+1)) - list(str(i+1)).count('0') == K:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())

p=0
while 10**(p+1)<=n:
    p+=1 #10**p<=n<10**(p+1)

m=0
l=[]
if k==1:
    if p==0:
        m=n
    else:
        m=9
        for i in range(1,p):
            m+=9
        for i in range(9):
            if (i+1)*(10**p)<=n:
                m+=1
    
elif k==2:
    if p==0:
        m=0
    elif p==1:
        m=n-9-n//10
    else:
        for i in range(1,p):
            m+=i*9*9
        for i in range(p):
            for j in range(1,10):
                for q in range(1,10):
                    if j*(10**p)+q*(10**i)<=n:
                        m+=1
    
elif k==3:
    if p==0:
        m=0
    elif p==1:
        m=0
    else:
        for i in range(2,p):
            m+=i*(i-1)*9*9*9//2
        for i in range(1,p):
            for s in range(i):
                for j in range(1,10):
                    for q in range(1,10):
                        for r in range(1,10):
                            if j*(10**p)+q*(10**i)+r*(10**s)<=n:
                                m+=1
print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
c = 0
for i in range(1, n+1):
    s = str(i)
    num = s.count('0')
    if len(s) - num == k:
        c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
cnt = int(input())
res = 0
for i in range(num):
  tmp =0
  for j in str(i+1):
    if j != '0':
      tmp+=1
  if cnt == tmp:
    res +=1
print(res)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
K = int(input())
www = 0
zzz = 0
yyy = 0
for x in range(num + 1):
  if x == 0:
    	continue
  numstr=str(x) 
  list_num = list(numstr)
  www = len(list_num)
  zzz = list_num.count("0")
  if K == (www - zzz):
  	yyy += 1
  else:
    continue
print(yyy)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())

p=0
while 10**(p+1)<=n:
    p+=1 #10**p<=n<10**(p+1)

m=0
l=[]
if k==1:
    if p==0:
        m=n
    else:
        m=9
        for i in range(1,p):
            m+=9
        for i in range(9):
            if (i+1)*(10**p)<=n:
                m+=1
    
elif k==2:
    if p==0:
        m=0
    elif p==1:
        m=n-9-n//10
    else:
        for i in range(1,p):
            m+=i*9*9
        for i in range(p):
            for j in range(1,10):
                for q in range(1,10):
                    if j*(10**p)+q*(10**i)<=n:
                        m+=1
    
elif k==3:
    if p==0:
        m=0
    elif p==1:
        m=0
    else:
        for i in range(2,p):
            m+=i*(i-1)*9*9*9//2
        for i in range(1,p):
            for j in range(1,10):
                for q in range(1,10):
                    for r in range(1,10):
                        for s in range(i):
                            if j*(10**p)+q*(10**i)+r*(10**s)<=n:
                                m+=1
print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count_not_zero = int(input())
ans = 0

for i in range(n + 1):
    if len(str(i)) - str(i).count("0") == count_not_zero :
        ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
K=int(input())
i=1
m=0
for i in range(N+1):
    k=str(i)
    l=(len(k))
    n=k.count('0')
    g=l-n
    i+=1
    if K == g:
        m+=1
    

print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())

from collections import Counter
count = 0
for i in range(0, n+1):
    s = str(i).replace('0', '')
    if sum(Counter(s).values()) == k:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
K=int(input())
an_cnt=0
for i in range(N+1):
    cnt=0
    moji=list(str(i))
    for m in moji:
        if m!='0':
            cnt+=1
    if cnt==K:
        
        an_cnt+=1
print(an_cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
l = []
a = 0
b = 0
o = []

for i in range(1,n+1):
    for j in range(len(str(i))):
        if str(i)[j] != '0':
            b += 1
    l.append(b)
    b = 0
    
for m in range(n):
    if l[m] == k:
        a += 1
        
print(a)

Submission status: Time Limit Exceeded

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

coun=0
for i in range(1,N+1):
    i=str(i)
    if str(i).count('0')==len(i)-K:
        coun+=1

print(coun)

Submission status: Time Limit Exceeded

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

res = 0
if K == 1:
    for i in range(1,10):
        for j in range(len(str(N))):
            if i*10**j <= N:
                res += 1
if K == 2:
    for i1 in range(1,10):
        for i2 in range(1,10):
            for j1 in range(len(str(N))-1):
                for j2 in range(len(str(N))-1-j1):
                    if i1*10**(j1+j2+1)+i2*10**j2 <= N:
                        res += 1

if K == 3:
    for j1 in range(len(str(N))-2-1):
        for j2 in range(len(str(N))-2-1-j1):
            for j3 in range(len(str(N))-2-1-j1-j2):
                res += 1
    res = res * (9**3)
    
    for i1 in range(1,10):
        for i2 in range(1,10):
            for i3 in range(1,10):
                for j1 in range(len(str(N))-2):
                    for j2 in range(len(str(N))-2-j1):
                        j3 = len(str(N))-2-j1-j2-1
                        if i1*10**(j1+j2+j3+2)+i2*10**(j2+j3+1)+i3*10**+j3 <= N:
                            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = input().strip()
K = input().strip()
cnt = len([i for i in range(int(N)) if len(str(i+1).replace('0', '')) == int(K)])
print(cnt)

Submission status: Time Limit Exceeded

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

lis1toN = [str(i) for i in range(1,N+1)]
lis_not0count = list(map(lambda x:len(x) - x.count('0'), lis1toN))

res = lis_not0count.count(K)
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
l = []
b = 0
o = []

for i in range(1,n+1):
    for j in range(len(str(i))):
        if str(i)[j] != '0':
            b += 1
    l.append(b)
    b = 0
    
for m in range(n):
    if l[m] == k:
        o.append(m)
        
print(len(o))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
k = int(input())
if k == 1:
  flag = True
  cnt = 0
  while flag:
    for i in range(101):
      for j in range(1,10):
        if j*(10**i) <= n:
          cnt += 1
        else:
          flag = False
          break
elif k == 2:
  flag = True
  cnt = 0
  while flag:
    for i in range(1,101):
      for j in range(1,10):
        for l in range(i):
          for m in range(1,10):
            if j*(10**i)+m*(10**l) <= n:
              cnt += 1
            else:
              flag = False
              break
else:
  flag = True
  cnt = 0
  while flag:
    for i in range(2,25):
      for j in range(1,10):
        for l in range(1,i):
          for m in range(1,10):
            for o in range(l):
              for p in range(1,10):
                if j*(10**i)+m*(10**l)+p*(10**o) <= n:
                  cnt += 1
                else:
                  flag = False
                  break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
p=[input() for i in range(2)]
N=int(p[0])
K=int(p[1])
cnt=0
for a in range(N):
    a+=1
    a=str(a)
    a=list(a)
    a=[int(s) for s in a]
    cnt2=(len(a))-(a.count(0))
    if cnt2==K:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

if K == 1:
    n = 0
elif K == 2:
    n = 10
else:
    n = 100

count = 0
for i in range(n, N+1):
    check = 0
    for s in str(i):
        if s != '0':
            check += 1
    if check == K:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=int(input())
count=0
for i in range(10**(k-1),n+1):
  s=str(i)
  n=len(s)
  if n-s.count('0')==k:
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
K = int(input())
count = 0

if K == 1:
  N = str(N)
  keta = len(N)
  str_keta = str(keta)
  count += int(N[0])
  count += (len(N)-1)*9
else:
  for i in range(N+1):
    if i == 0:
      pass
    else:
      i = str(i)
      i = i.replace("0", "")
      len_i = len(i)
      if len_i == K:
        count += 1
        
print(count)