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)

use std::vec::Vec;

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 read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


/*
dp[i][j][k] = { j = 0 ならば，先頭からi桁がK未満で，あまりがjとなる数の総数
            　　 j = 1 ならば，先頭からi桁がKと等しくで，あまりがjとなる数の総数 
              }
dp[0][1][0] = 1 //未満ではない，K[-1] = 0と考える．
dp[i+1][0][k] = for l = 0..10 { dp[i][0][ (k-l) mod D] } + for l = 0..K[i] { dp[i][1][(k - l) mod D] }
dp[i+1][1][k] = dp[i][1][(k - K[i]) mod D]
*/
const MOD: usize = 1_000_000_000 + 7;
fn main() {
    let K: Vec<usize> = read::<String>().chars().map(|e| e as usize - '0' as usize).collect();
    let D: usize = read();
    let n = K.len();
    let mut dp = vec![vec![vec![0; D]; 2]; n+1];
    
    // 
    dp[0][1][0] = 1;

    for i in 0..n {   
        for k in 0..D {
            for l in 0..10 {
                // 未満の場合の更新式
                dp[i+1][0][k] += dp[i][0][(k + 10 * D - l) % D];
                dp[i+1][0][k] %= MOD;

                if l < K[i] {
                    dp[i+1][0][k] += dp[i][1][(k + 10 * D - l) % D];
                    dp[i+1][0][k] %= MOD;
                }
            }
            // 一致している場合の更新式
            dp[i+1][1][k] += dp[i][1][(k + 10 * D - K[i]) % D];
            dp[i+1][1][k] %= MOD;
        }
    }

    let ans: usize = (dp[n][0][0] + dp[n][1][0]) % MOD;
    println!("{}", ans-1); // 0000...0000の場合を除く
}