#include using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; template struct modint { lint v; modint() : v(0) {} modint(signed v) : v(v) {} modint(lint t) { v = t % mod; if (v < 0) v += mod; } modint pow(lint k) { modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static modint add_identity() { return modint(0); } static modint mul_identity() { return modint(1); } modint inv() { return pow(mod - 2); } modint &operator+=(modint a) { v += a.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(modint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } modint &operator*=(modint a) { v = v * a.v % mod; return *this; } modint &operator/=(modint a) { return (*this) *= a.inv(); } modint operator+(modint a) const { return modint(v) += a; }; modint operator-(modint a) const { return modint(v) -= a; }; modint operator*(modint a) const { return modint(v) *= a; }; modint operator/(modint a) const { return modint(v) /= a; }; modint operator-() const { return v ? modint(mod - v) : modint(v); } bool operator==(const modint a) const { return v == a.v; } bool operator!=(const modint a) const { return v != a.v; } bool operator<(const modint a) const { return v < a.v; } }; using mint = modint; ostream &operator<<(ostream &os, mint m) { return os << m.v; } struct Combination { vector fac, finv, inv; Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) { maxN += 100; // for safety fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint i = 2; i <= maxN; ++i) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } lint operator()(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } }; int digsum(lint d) { while (d / 10 != 0) { lint t = 0; while (d) { t += d % 10; d /= 10; } d = t; } return d; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string t; cin >> t; int d; cin >> d; lint q = 0; lint dig = 0; // for (lint i = 12390875213; i < 12390875213 + 1000; ++i) { // cout << digsum(i) << "\n"; // } for (int i = 0; i < (int)t.size(); ++i) { if (t[i] == '?') q++; else dig += t[i] - '0'; } if (q == 0) { if (digsum(dig) == d) cout << 1 << "\n"; else cout << 0 << "\n"; return 0; } if (d == 0) { if (dig == 0) cout << 1 << "\n"; else cout << 0 << "\n"; return 0; } // 0 - 99999... (9 * q) lint rem = 1; mint ret = 0; mint one = 1; for (int i = 0; i < q; ++i) { rem *= 10; rem %= 9; ret += one; one *= 10; } if ((d + 10 - dig) % 10 < rem) ret += 1; cout << ret << "\n"; return 0; }