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

Solution in Python (3.8.2) (judge verdict: Wrong Answer)

# 314159, 2,
# 0[xxxxx] 5C2 * 9*9 = 810
# 1[xxxxx] 5C1 * 9 = 45
# 2[xxxxx] 5C1 * 9 = 45
# 3[xxxxx] わからん!
# 31[0000] = 1
# 30[xxxx] = 4C1 * 9 合わせて937

# 9999, 3,
# 0[xxx] 3C3 * 9*9*9 = 729
# [yxxx] y=8, x=3C2 * 9*9 = 8 * 243
# 9[xxx] = 3C2 * 9*9 = 243

# 94599, 3,
# 0[xxxx] 4C3 * 9*9*9 = 4 * 729
# 1[xxxx] x=4C2 * 9*9 = 6 * 81
# ...
# 8[xxxx] x=4C2 * 9*9 = 6 * 81
# 94[x]00 = 5
# 940[xx] 2C1 * 9
# 93[xxx] 3C1 * 9
str_n = input()
n = int(str_n)
k = int(input())

if k > len(str_n):
  print(0)
  exit()

head = n
while head >= 10:
  head //= 10
def choice(p, q):
  if p == q:
    return 1
  res = 1
  for i in range(q):
    res = (res * p)
    p -= 1
  for i in range(q):
    res = res // (i+1)
  return res

ans = choice(len(str_n)-1, k) * (9 ** k)
for i in range(1, head):
  ans += choice(len(str_n)-1, k-1) * (9 ** (k-1))
if k == 3:
  ans += int(str_n[2])  # 99x0000
  ans += choice(len(str_n) - 3, 1) * 9  # 990xxx
  ans += (int(str_n[1])-1) * choice(len(str_n) - 2, 1) * 9  # 9[1:8]xxxx
  ans += choice(len(str_n) - 2, 2) * 9*9  # 90xxxxx
if k == 2:
  ans += int(str_n[1])
  ans += choice(len(str_n) - 2, 1) * 9
if k == 1:
  ans += int(str_n[0]) if len(str_n) > 1 else 1

print(ans)