/** * @FileName a.cpp * @Author kanpurin * @Created 2022.10.30 10:21:42 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template< int MOD > struct mint { public: unsigned int x; mint() : x(0) {} mint(long long v) { long long w = (long long)(v % (long long)(MOD)); if (w < 0) w += MOD; x = (unsigned int)(w); } mint(std::string &s) { unsigned int z = 0; for (int i = 0; i < s.size(); i++) { z *= 10; z += s[i] - '0'; z %= MOD; } x = z; } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint& operator+=(const mint &a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint &a) { if ((x -= a.x) >= MOD) x += MOD; return *this; } mint& operator*=(const mint &a) { unsigned long long z = x; z *= a.x; x = (unsigned int)(z % MOD); return *this; } mint& operator/=(const mint &a) {return *this = *this * a.inv(); } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return lhs.x == rhs.x; } friend bool operator!=(const mint& lhs, const mint& rhs) { return lhs.x != rhs.x; } friend std::ostream& operator<<(std::ostream &os, const mint &n) { return os << n.x; } friend std::istream &operator>>(std::istream &is, mint &n) { unsigned int x; is >> x; n = mint(x); return is; } mint inv() const { assert(x); return pow(MOD-2); } mint pow(long long n) const { assert(0 <= n); mint p = *this, r = 1; while (n) { if (n & 1) r *= p; p *= p; n >>= 1; } return r; } mint sqrt() const { if (this->x < 2) return *this; if (this->pow((MOD-1)>>1).x != 1) return mint(0); mint b = 1, one = 1; while (b.pow((MOD-1) >> 1) == 1) b += one; long long m = MOD-1, e = 0; while (m % 2 == 0) m >>= 1, e += 1; mint x = this->pow((m - 1) >> 1); mint y = (*this) * x * x; x *= (*this); mint z = b.pow(m); while (y.x != 1) { int j = 0; mint t = y; while (t != one) j += 1, t *= t; z = z.pow(1LL << (e-j-1)); x *= z; z *= z; y *= z; e = j; } return x; } }; constexpr int MOD = 1e9 + 7; struct Monoid { mint val; mint leading_zero; bool undef = true; Monoid() { *this = zero(); } Monoid(mint val, mint leading_zero, bool undef = true) : val(val), leading_zero(leading_zero), undef(undef) {} static Monoid zero() { return Monoid(0,0); } static Monoid e() { return Monoid(0,1,false); } Monoid& operator+=(const Monoid &a) { if (this->undef) *this = a; else if (!a.undef) { this->val += a.val; this->leading_zero += a.leading_zero; } return *this; } Monoid& operator*=(int c) { if (c == 0) { this->val = 0; } else { this->val = this->val*c + this->leading_zero*c; this->leading_zero = 0; } return *this; } friend Monoid operator+(const Monoid& a, const Monoid& b) { return Monoid(a) += b; } friend Monoid operator*(const Monoid& a, int c) { return Monoid(a) *= c; } friend std::ostream& operator<<(std::ostream &os, const Monoid &x) { return os << x.val; } }; struct Automaton { vector> delta; vector is_accept, is_reject; int init; int alphabet_size = 10; int next(int state, int c) const { return delta[state][c]; } bool accept(int state) const { return is_accept[state]; } bool reject(int state) const { return is_reject[state]; } int size() const {return delta.size(); } }; struct SimpleAutomaton : public Automaton { private: void set_init() { init = 0; } void set_delta() { int qsize = 1; delta.resize(qsize,vector(alphabet_size)); for (int c = 0; c < alphabet_size; c++) { delta[0][c] = 0; } } void set_is_accept() { int qsize = 1; is_accept.resize(qsize); for (int state = 0; state < qsize; state++) { is_accept[state] = true; } } void set_is_reject() { int qsize = 1; is_reject.resize(qsize); for (int state = 0; state < qsize; state++) { is_reject[state] = false; } } public: SimpleAutomaton(int alpha_size = 10) { alphabet_size = alpha_size; set_init(); set_delta(); set_is_accept(); set_is_reject(); } }; template Monoid digitDP(const string &s, const Automaton &dfa, bool eq = 1) { vector alpha(dfa.alphabet_size); iota(alpha.begin(), alpha.end(), 0); vector> dp(2,vector(dfa.size(),Monoid::zero())); dp[1][dfa.init] = Monoid::e(); for (int i = 0; i < s.size(); i++) { vector> dp2(2,vector(dfa.size(),Monoid::zero())); for (int tight = 0; tight <= 1; tight++) { for (int state = 0; state < dfa.size(); state++) { if (dfa.reject(state) || dp[tight][state].undef) continue; int lim = (tight ? s[i] - '0' : dfa.alphabet_size - 1); for (int c = 0; c <= lim; c++) { int tight_ = tight && c == lim; int state_ = dfa.next(state,c); if (dfa.reject(state_)) continue; dp2[tight_][state_] += dp[tight][state]*c; } } } dp = dp2; } Monoid ans = Monoid::zero(); for (int tight = 0; tight <= eq; tight++) for (int state = 0; state < dfa.size(); state++) if (dfa.accept(state)) ans += dp[tight][state]; return ans; } int main() { string n;cin >> n; cout << digitDP(n,SimpleAutomaton()) << endl; return 0; }