#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; }; } ssize_t ceil_pow2(ssize_t s) { ssize_t ret = 1; while (ret < s) ret *= 2; return ret; } namespace segtree { template struct SegmentTree { vec nodes; Op op; T id_ele; auto get_children_idx(ssize_t idx) const -> std::pair { return std::make_pair(2 * idx + 1, 2 * idx + 2); } T get_merged(ssize_t idx) const { ssize_t a, b; std::tie(a, b) = get_children_idx(idx); return op(nodes[a], nodes[b]); } public: SegmentTree(const vec &init_v, Op op, T id_ele) : op(op), id_ele(id_ele) { build(init_v); } void build(const vec &v) { nodes.resize(ceil_pow2(v.size()) * 2 - 1, id_ele); ssize_t sz = size(); std::copy(ALL(v), nodes.begin() + sz - 1); build_parents(); } void build_parents() { ssize_t sz = size(); for (ssize_t i = sz - 2; 0 <= i; i--) nodes[i] = get_merged(i); } ssize_t size() const { return (nodes.size() + 1) / 2; } const T& operator [](ll idx) const { return nodes[idx + size() - 1]; } T get_query(ll ql, ll qr) const { return get_query(ql, qr, id_ele); } T get_query(ll ql, ll qr, T init) const { T ret = init; ssize_t lnode = ql + size(), rnode = qr + size(); while (lnode < rnode) { if (lnode & 1) { ret = std::move(op(nodes[lnode - 1], ret)); lnode++; } if (rnode & 1) { rnode--; ret = std::move(op(ret, nodes[rnode - 1])); } lnode /= 2; rnode /= 2; } return ret; } void update_query(ll idx, T val) { idx += size() - 1; nodes[idx] = val; while (idx) { ll pidx = (idx - 1) / 2; nodes[pidx] = get_merged(pidx); idx = pidx; } } template ssize_t lower_bound(F f) const { T sum = id_ele; ssize_t l = 0, r = size(), idx = 0, bidx = 0; if (!f(nodes[0])) return -1; while (true) { if (r - l == 1) { if (!f(sum)) bidx++; break; } auto lidx = 2 * idx + 1; auto ridx = lidx + 1; T nsum = op(sum, nodes[lidx]); ssize_t m = (l + r) / 2; if (f(nsum)) { r = m; idx = lidx; } else { l = m; idx = ridx; bidx = m; sum = std::move(nsum); } } return bidx; } }; } const ll mod = 1e9 + 7; const ssize_t SIZE = 1e6; using mint = math::Modint; std::array dp; std::array dp2; int main() { 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++; } dp[0] = 1; for (ll i = 0; i < 10; i++) dp2[i] = i; for (ll i = 0; i < cnt; i++) { ll maxv = i * 9; for (ll j = maxv; 0 <= j; j--) { for (ll k = 1; k <= 9; k++) dp[j + k] += dp[j]; } } auto to_digsum = [](ll n) { ll ret = 0; while (n) { ret += n % 10; n /= 10; } return ret; }; for (ll i = 10; i < SIZE; i++) dp2[i] = dp2[to_digsum(i)]; mint ans = 0; for (ll i = 0; i <= cnt * 9; i++) { ll v = sum + i; ll ds = dp2[v]; if (ds == d) ans += dp[i]; } std::cout << ans.value() << "\n"; return 0; }