#define CPP17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef CPP17 #include #endif // Yay!! #define endl codeforces // macros for iterator #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) // alias using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair; using tii = std::tuple; using pll = std::pair; using tll = std::tuple; template using vec = std::vector; template using vvec = vec>; // variadic min/max template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } // variadic chmin/chmax template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } // multi demension array template struct multi_dim_array { using type = std::array::type, Head>; }; template struct multi_dim_array { using type = std::array; }; template using mdarray = typename multi_dim_array::type; #ifdef CPP17 // fill container template void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } } #endif // make multi dimension vector template vec make_v(ssize_t sz) { return vec(sz); } template auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v(std::forward(ts)...)); return vec(hs, v); } // init namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } namespace math { template constexpr T pow(const T &n, ll k) { T ret = n.mul_id_ele(); T cur = n; while (k) { if (k & 1) ret *= cur; cur *= cur; k /= 2; } return ret; } } namespace math { template struct Modint { constexpr Modint(ll x) noexcept : x((Mod + x % Mod) % Mod) { } constexpr Modint() noexcept : Modint(0) { } constexpr Modint add_id_ele() const noexcept { return Modint(0); } constexpr Modint mul_id_ele() const noexcept { return Modint(1); } constexpr ll& value() noexcept { return x; } constexpr ll value() const noexcept { return x; } constexpr Modint& operator +=(const Modint &oth) noexcept { x += oth.value(); if (Mod <= x) x -= Mod; return *this; } constexpr Modint& operator -=(const Modint &oth) noexcept { x += Mod - oth.value(); if (Mod <= x) x -= Mod; return *this; } constexpr Modint& operator *=(const Modint &oth) noexcept { x *= oth.value(); x %= Mod; return *this; } constexpr Modint& operator /=(const Modint &oth) noexcept { x *= oth.inv().value(); x %= Mod; return *this; } constexpr Modint operator +(const Modint &oth) const noexcept { return Modint(x) += oth; } constexpr Modint operator -(const Modint &oth) const noexcept { return Modint(x) -= oth; } constexpr Modint operator *(const Modint &oth) const noexcept { return Modint(x) *= oth; } constexpr Modint operator /(const Modint &oth) const noexcept { return Modint(x) /= oth; } constexpr Modint operator -() const noexcept { return Modint((x != 0) * (Mod - x)); } template constexpr typename std::enable_if::value, const Modint&>::type operator =(T t) noexcept { (*this) = Modint(std::forward(t)); return *this; } constexpr Modint inv() const noexcept { return ::math::pow(*this, Mod - 2); } constexpr ll mod() const noexcept { return Mod; } private: ll x; }; } const ll mod = 1e9 + 7; const ssize_t SIZE = 1e6; using mint = math::Modint; mdarray dp; mint solve() { std::string s; ll d; std::cin >> s >> d; ll sum = 0, cnt = 0; for (char c : s) { if ('0' <= c && c <= '9') sum += c - '0'; else cnt++; } if (d == 0) return mint(sum == 0); dp[0][sum % 9] = 1; for (ll i = 0; i < cnt; i++) { for (ll j = 0; j < 9; j++) for (ll k = 0; k < 10; k++) { ll m = (j + k) % 9; dp[i + 1][m] += dp[i][j]; } } return dp[cnt][d % 9]; } int main() { std::cout << solve().value() << "\n"; return 0; }