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)

#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;
use std::mem::*;
use std::cell::*;

struct Input {
    stdin: io::Stdin,
    buf: VecDeque<String>
}

impl Input {
    fn new() -> Input {
        Input { 
            stdin: io::stdin(),
            buf: VecDeque::new()
        }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_2<T: FromStr, U: FromStr>(&mut self) -> (T, U)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug {
        (self.read(), self.read())
    }

    fn read_3<T: FromStr, U: FromStr, V: FromStr>(&mut self) -> (T, U, V)
    where <T as FromStr>::Err: fmt::Debug,
          <U as FromStr>::Err: fmt::Debug,
          <V as FromStr>::Err: fmt::Debug {
        (self.read(), self.read(), self.read())
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = self.stdin.read_line(&mut s);
            self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
        }
        self.buf.pop_front()
    }
}

fn run() {
    let mut ip = Input::new();
    const MOD: i64 = 1000000007;
    let k = ip.read_bytes();
    let n = k.len();
    let d: usize = ip.read();
    let mut dp = vec![vec![[0; 2]; d + 1]; n + 1];
    dp[0][0][1] = 1;
    for i in 1..n + 1 {
        let y = (k[i - 1] - b'0') as usize;
        for j in 0..d {
            for x in 0..10 {
                if x <= y {
                    let k = if x == y { 1 } else { 0 };
                    dp[i][j][k] = (dp[i][j][k] + dp[i - 1][(j + x) % d][1]) % MOD;
                }
                dp[i][j][0] = (dp[i][j][0] + dp[i - 1][(j + x) % d][0]) % MOD;
            } 
        }
    }
    println!("{}", dp[n][0][0] + dp[n][0][1] - 1);
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(50 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}