// -----------------------------------------------------------------------
// 1. aの各位の数字の和 mod 9 = a mod 9 であることを利用する
// 2. そうするとDP[i][j]のjの値によっては確実に0となるようなところがある。
// 3. そのようなとことを探索しない。
// 4. 計算量はO(|N|*D), 定数は約9分の1
// -----------------------------------------------------------------------
#include <string>
#include <iostream>
#define mod 1000000007
using namespace std;
string s; int d, sum, ret, dp[111][11119];
int main() {
cin >> s >> d;
dp[0][0] = 1;
for(int i = 1; i <= s.size(); i++) {
sum += s[i - 1] - 48; sum %= 9;
for(int j = 0; j * 9 + sum <= d; j++) {
int x = 0, t = 1;
for(int k = 1; i >= k; k++) {
if(t <= j * 9 + sum) x += (s[i - k] - 48) * t, t *= 10;
else if(s[i - k] != 48) break;
if(x > j * 9 + sum) break;
dp[i][j] = (dp[i][j] + dp[i - k][(j * 9 + sum - x) / 9]) % mod;
}
}
}
for(int i = 0; i * 9 + sum <= d; i++) ret = (ret + dp[s.size()][i]) % mod;
printf("%d\n", ret);
}
Ly8gLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KLy8gMS4gYeOBruWQhOS9jeOBruaVsOWtl+OBruWSjCBtb2QgOSA9IGEgbW9kIDkg44Gn44GC44KL44GT44Go44KS5Yip55So44GZ44KLCi8vIDIuIOOBneOBhuOBmeOCi+OBqERQW2ldW2pd44GuauOBruWApOOBq+OCiOOBo+OBpuOBr+eiuuWun+OBqzDjgajjgarjgovjgojjgYbjgarjgajjgZPjgo3jgYzjgYLjgovjgIIKLy8gMy4g44Gd44Gu44KI44GG44Gq44Go44GT44Go44KS5o6i57Si44GX44Gq44GE44CCCi8vIDQuIOioiOeul+mHj+OBr08ofE58KkQpLCDlrprmlbDjga/ntIQ55YiG44GuMQovLyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS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