#include using namespace std; static const long long MOD = 998244353; // 状態キー // (leading zero, 状態, 未満フラグ) struct State { bool lz; int st; bool lt; bool operator<(const State& other) const { if (lz != other.lz) return lz < other.lz; if (st != other.st) return st < other.st; return lt < other.lt; } }; vector> transition(const State& k, long long v, int x) { vector> res; bool lz = k.lz; int st = k.st; bool lt = k.lt; if (lz) { for (int d = 1; d <= 9; d++) { int nst = (d == 4 ? 1 : 0); res.push_back({{false, nst, true}, 1}); } // leading zero 維持 res.push_back({{true, 0, true}, 1}); } else { for (int d = 0; d <= 9; d++) { if (!lt && d > x) break; if (st == 2 && d == 4) continue; // 404 を禁止 int nst = 0; if (st == 0 && d == 4) nst = 1; else if (st != 0 && d == 4) nst = 1; else if (st == 1 && d == 0) nst = 2; bool nlt = lt || (d < x); res.push_back({{false, nst, nlt}, v}); } } return res; } map accum_dp( const vector& xs, map init, bool is_reset = true ) { map dp = init; for (int x : xs) { map pp; if (!is_reset) pp = dp; swap(dp, pp); for (auto& [fm_key, fm_val] : pp) { auto nexts = transition(fm_key, fm_val, x); for (auto& [to_key, to_val] : nexts) { long long& ref = dp[to_key]; ref = (ref + to_val) % MOD; } } } return dp; } int main() { string N; cin >> N; vector digits; for (char c : N) digits.push_back(c - '0'); map init; init[{true, 0, true}] = 1; for (int d = 1; d <= digits[0]; d++) { bool lz = false; int st = (d == 4 ? 1 : 0); bool lt = (d < digits[0]); init[{lz, st, lt}]++; } vector rest(digits.begin() + 1, digits.end()); auto dp = accum_dp(rest, init); long long res = 0; for (auto& [k, v] : dp) { if (k.lz) continue; res = (res + v) % MOD; } cout << res << '\n'; return 0; }