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 C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#define rep(n) for(int i=0;i<(n);i++)
#define rep1(n) for(int i=1;i<=(n);i++)
#define all(n) n.begin(),n.end()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define pb push_back
ll dp[10005][105];
const ll mod = 1000000007;

signed main(){
    dp[0][0] = 1;
    string s;
    int d;
    cin>>s;
    cin>>d;
    int siz = s.size();
    assert(siz==3);
    for(int i=1;i<=siz;i++){
      for(int j=0;j<d;j++){
        for(int k=0;k<10;k++){
          int tmp = j-k;
          tmp = (tmp%d+d)%d;
          dp[i][j] += dp[i-1][tmp];
          dp[i][j] %= mod;
        }
      }
    }

        int nsiz = siz;
        int acu = 0;
        int idx = 0;
        ll ans = 0;
        nsiz--;
        while(nsiz>=0){
          for(int i=0;i<s[idx]-'0';i++){
            int tmp = -i-acu;
            tmp = (tmp%d+d)%d;
            //cout<<nsiz<<" "<<tmp<<'\n';
            ans += dp[nsiz][tmp];
            ans %= mod;
          }
          acu += s[idx]-'0';
          idx++;
          nsiz--;
        }



        if(acu%d==0)ans++;
        ans--;

        cout<<ans<<'\n';



}