#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair P; typedef complex com; constexpr int inf = 1000000000; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } constexpr ll mod = 1000000007; ll dp[100010][9]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); string t; cin >> t; int d; cin >> d; bool allzero = true; int n = t.size(); rep(i, n) if (t[i] != '0'&&t[i] != '?') allzero = false; dp[0][0] = 1; rep(i, n) { rep(j, 9) { if (t[i] == '?') { rep(k, 10) { dp[i + 1][(j + k) % 9] += dp[i][j]; dp[i + 1][(j + k) % 9] %= mod; } } else { int k = t[i] - '0'; dp[i + 1][(j + k) % 9] += dp[i][j]; dp[i + 1][(j + k) % 9] %= mod; } } } if (d == 0 && !allzero) cout << "0\n"; else if (d == 0 && allzero) cout << "1\n"; else if (d == 9 && !allzero) cout << dp[n][0] << '\n'; else if (d == 9 && allzero) cout << (dp[n][0] + mod - 1) % mod << '\n'; else cout << dp[n][d] << '\n'; }