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)

#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e4 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int dp[N][102][2];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	string k;	int d;
	cin >> k >> d;
	dp[0][0][1] = 1;
	for(int i = 0; i < (int)k.length(); i++){
		for(int x = 0; x < 2; x++){
			for(int d1 = 0; d1 < d; d1++){
				if(x == 0){
					for(int j = 0; j < 10; j++)
						dp[i+1][(d1 + j) % d][x] = (dp[i+1][(d1 + j) % d][0] + dp[i][d1][0]) % mod;
				}
				else{
					int v = k[i]-'0';
					for(int j = 0; j < v; j++)
						dp[i+1][(d1 + j) % d][0] = (dp[i+1][(d1 + j) % d][0] + dp[i][d1][1]) % mod;
					dp[i+1][(d1 + v) % d][1] = (dp[i+1][(d1 + v) % d][1] + dp[i][d1][1]) % mod;
				}
			}
		}
	}
	cout << (dp[k.length()][0][0] + dp[k.length()][0][1] - 1) % mod;
	return 0;
}