Problem:
Score : 100 points

Problem Statement

Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:

The sum of the digits in base ten is a multiple of D.

Constraints

All values in input are integers.

1 \leq K < 10^{10000}

1 \leq D \leq 100

Input

Input is given from Standard Input in the following format:

K
D

Output

Print the number of integers satisfying the condition, modulo 10^9 + 7.

Sample Input 1

30
4

Sample Output 1

6

Those six integers are: 4, 8, 13, 17, 22 and 26.

Sample Input 2

1000000009
1

Sample Output 2

2

Be sure to print the number modulo 10^9 + 7.

Sample Input 3

98765432109876543210
58

Sample Output 3

635270834

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n: String = read();
    let d: usize = read();
    let mut dp = vec![vec![vec![0; d]; 2]; n.len() + 1];
    let big_int = 1000_000_000 + 7;
    dp[0][0][0] = 1;  // pos, less, d

    for (i, c) in n.chars().enumerate() {
        for j in 0..2 {
            for m in 0..d {
                let lim = if j == 1 { 9 } else { c.to_digit(10).unwrap() };
                for l in 0..lim + 1 {
                    let idx1 = if j == 1 || l < lim { 1 } else { 0 };
                    let idx2: usize = (m + l as usize) % d;
                    dp[i + 1][idx1][idx2] += dp[i][j][m];
                    dp[i + 1][idx1][idx2] %= big_int;
                }
            }
        }
    }
    // println!("{:?}", dp);

    let mut ans = 0;
    for j in 0..2 {
        ans += dp[n.len()][j][0];
        ans %= big_int;
    }
    println!("{:?}", ans - 1);
}