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.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_string()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as u64)
        .collect::<Vec<u64>>();

    let k = read_as_vec::<usize>()[0];

    if n.len() < k{
        println!("0");
        return;
    }

    if n.len() == 1{
        println!("{}",n[0]);
        return;
    }

    let mut dp0: Vec<Vec<u64>> = vec![vec![0;3];n.len()]; // undecided
    let mut dp1: Vec<Vec<u64>> = vec![vec![0;3];n.len()]; // decided
    dp0[0][0] = 1;
    dp1[0][0] = n[0]-1;

    for i in 1..n.len(){
        if n[i] == 0{
            dp0[i][0] = dp0[i-1][0];
            dp0[i][1] = dp0[i-1][1];
            dp0[i][2] = dp0[i-1][2];
        }else{
            dp0[i][0] = 0;
            dp0[i][1] = dp0[i-1][0];
            dp0[i][2] = dp0[i-1][1];

            dp1[i][0] += dp0[i-1][0];
            dp1[i][1] += (n[i]-1) * dp0[i-1][0] + dp0[i-1][1];
            dp1[i][2] += (n[i]-1) * dp0[i-1][1] + dp0[i-1][2];
        }


        dp1[i][0] += 9 + dp1[i-1][0];
        dp1[i][1] += dp1[i-1][0]*9 + dp1[i-1][1];
        dp1[i][2] += dp1[i-1][1]*9 + dp1[i-1][2];
    }

    dbg!(&dp0);
    dbg!(&dp1);

    println!("{}", dp0[n.len()-1][k-1] + dp1[n.len()-1][k-1]);

}

*/

fn main() {
    let exe = "./binXXXXXX";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";