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 Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(unused_imports)]
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;
use std::str::FromStr;

type Error = Box<dyn std::error::Error>;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct Scanner {
    buff: Vec<String>,
    pos: usize,
}


#[allow(dead_code)]
impl Scanner {
    pub fn new() -> Self {
        Scanner {
            buff: Vec::new(),
            pos: 0,
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T {
        while self.buff.len() <= self.pos {
            self.pos = 0;
            self.buff = read_line().split_whitespace().map(|s| s.to_owned()).collect();
        }

        let result = self.buff[self.pos].parse::<T>();
        self.pos += 1;
        result.ok().unwrap()
    }

    pub fn next_line(&mut self) -> String {
        let result  = read_line().trim().to_owned();
        self.buff.clear();
        self.pos = 0;

        result
    }

    pub fn next_vec<T: FromStr>(&mut self) -> Vec<T> {
        self.buff.clear();
        self.pos = 0;
        read_line().trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect()
    }
    
    pub fn next_line_chars(&mut self) -> Vec<char> {
        let result  = read_line().trim().chars().collect();
        self.buff.clear();
        self.pos = 0;

        result
    }
}

fn func(n: &Vec<char>, idx: usize, k: usize) -> u64 {
    if idx >= n.len() {
        if k==0 {
            return 1;
        }

        return 0;
    }
    if n[idx] == '0' {
        return 0;
    }
    if k==0 {
        return 0;
    }

    let m = n.len();
    let p = (n[idx] as u8 - '0' as u8) as u64;
    let mut tmp = dbg!((p-1) * func2(m-idx, k-1));
    dbg!(tmp + func(n, idx+1, k-1) + func2(m-idx-1, k-1))
}

fn func2(m: usize, k: usize) -> u64 {
    if m < k || m == 0 {
        return 0;
    }
    let mut tmp = 1;

    for _i in 0..k {
        tmp *= 9 as u64;
    }

    for i in 0..k {
        tmp *= (m-i-1) as u64;
    }
    for i in 0..k {
        tmp /= (i+1) as u64;
    }
    dbg!(tmp)
}


fn main() {
    let mut sc = Scanner::new();

    let n: Vec<char> = sc.next_line_chars();
    let k: usize = sc.next();
    let mut m = n.len();

    let mut ans: u64 = 0;

    ans += func2(m, k);


    ans += func(&n, 0, k);

    println!("{}", ans);
}