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: Wrong Answer)

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse
// struct Edge {
//   int to, id;
//   Edge(int a, int b): to(a), id(b) {}
// };

ll dp[10010][2][110];


int main(int argc, char const *argv[])
{
	string s;int d;cin>>s>>d;

	int n = (int)s.size();


	dp[0][0][0]=1;


	rep(i,n) {
		rep(j,2) {
			rep(k,d) {
				int e = s[i]-'0';
				if (j==0) {
					dp[i+1][0][(k+e)%d]+=dp[i][j][k];
					dp[i+1][0][(k+e)%d]%=MOD;
					if (e>=1) {
						rep(l,e) {
							dp[i+1][1][(k+l)%d]+=dp[i][j][k];
							dp[i+1][1][(k+l)%d]%=MOD;
						}
					}
				} else {
					rep(l,10) {
						dp[i+1][1][(k+l)%d]+=dp[i][j][k];
						dp[i+1][1][(k+l)%d]%=MOD;
					}
				}
			}
		}
	}

	cout<<(dp[n][0][0]+dp[n][1][0])%MOD<<endl;


	return 0;
}