#include #include #include #include #include using namespace std; using ll = long long; int main () { string n; cin >> n; vector N(n.size()); for (int i = 0; i < n.size(); i++) N[i] = n[i] - '0'; const int len = static_cast(n.size()); const ll MOD = 998244353; const auto ban = vector({4, 0, 4}); map, ll> mp; auto dp = [&] (auto dp, int pos, bool less, int cur) { auto key = make_tuple(pos, less, cur); if (mp.find(key) != mp.end()) return mp[key]; if (pos == len) { if (cur == 3) return 0LL; return 1LL; } ll res = 0; for (int nex = 0; nex < 10; nex++) { if (!less && N[pos] < nex) continue; bool nl = less || nex < N[pos]; int nc = cur; if (nc < 3) { if (ban[nc] == nex) { nc++; } else if (nex == 4) { nc = 1; } else { nc = 0; } } res += dp(dp, pos + 1, nl, nc); res %= MOD; } return mp[key] = res; }; cout << dp(dp, 0, false, 0) - 1 << "\n"; }