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>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  int D; cin>>D;
  vii dp(N+1,vi(D));
  vi cp(N+1);
  int P=S[0]-'0';
  rep(i,0,P) dp[1][i]++;
  cp[1]=P%D;
  rep(i,1,N){
    int X=S[i]-'0';
    rep(j,0,D){
      rep(k,0,10){
        dp[i+1][(j+k)%D]+=dp[i][j];
        dp[i+1][(j+k)%D]%=MOD;
      }
    }
    rep(j,0,X){
      dp[i+1][(j+cp[i])%D]++;
      dp[i+1][(j+cp[i])%D]%=MOD;
    }
    cp[i+1]=cp[i]+X;
    cp[i+1]%=D;
  }
  int ans=dp[N][0]-1;
  if(cp[N]==0) ans++;
  ans%=MOD;
  cout<<ans<<endl;
  }