#include using namespace std; long long MOD = 1000000007; int main(){ string T; cin >> T; int D; cin >> D; int N = T.size(); bool zero = true; bool zero2 = true; for (int i = 0; i < N; i++){ if (T[i] != '0' && T[i] != '?'){ zero = false; } if (T[i] != '0'){ zero2 = false; } } if (D == 0){ if (zero){ cout << 1 << endl; } else { cout << 0 << endl; } } else { vector> dp(N + 1, vector(9, 0)); dp[0][0] = 1; for (int i = 0; i < N; i++){ if (T[i] == '?'){ for (int j = 0; j < 9; j++){ for (int k = 0; k <= 9; k++){ dp[i + 1][(j + k) % 9] += dp[i][j]; dp[i + 1][(j + k) % 9] %= MOD; } } } else { int d = T[i] - '0'; for (int j = 0; j < 9; j++){ dp[i + 1][(j + d) % 9] = dp[i][j]; } } } if (D == 9 && zero2){ cout << 0 << endl; } else { cout << dp[N][D % 9] << endl; } } }