#include using namespace std; long long MOD = 1000000007; int main(){ string T; cin >> T; int D; cin >> D; int N = T.size(); if (D == 0){ bool zero = true; for (int i = 0; i < N; i++){ if (T[i] != '0' && T[i] != '?'){ zero = false; } } 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]; } } } cout << dp[N][D % 9] << endl; } }