#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; // returns (len_of_cycle, first_in-cycle_index) template std::pair detect_cycle(F f, S x) { S p = x, q = x; int l = 0; int ub = 1; do { if (l == ub) { ub <<= 1; l = 0; p = q; } q = f(q); l++; } while(p != q); p = q = x; for(int it = l; it > 0; it--) q = f(q); int m = 0; while(p != q) p = f(p), q = f(q), m++; return {l, m}; } auto solve(ll n) { using mint1 = modint998244353; using mint2 = static_modint<998244352>; ll p10[19]; p10[0] = 1; rep(i, 18) p10[i+1] = 10 * p10[i]; n++; mint1 ans; mint2 len; for (int k = 1; p10[k-1] < n; k++) { ll l = p10[k - 1], r = min(p10[k], n); auto f = [&](mint2 x) { return 2 * x + k; }; auto g = [&](mint1 v, mint2 len) { mint1 c1 = mint1(10).pow(len.val()); mint1 c0 = c1 * mint1(10).pow(k) + 1; return pair(v * c0 + l * c1, f(len)); }; auto [period, idx] = detect_cycle(f, len); rep(_, idx) { if (l == r) break; tie(ans, len) = g(ans, len); l++; } if (l == r) continue; ll rest = r - l; ll q = rest / period, rem = rest % period; if (q) { vector c0s(period); { mint2 t = len; rep(i, period) { c0s[i] = mint1(10).pow(t.val() + k) + 1; t = f(t); } assert(t == len); } mint1 r = 1; rep(i, period) r *= c0s[i]; ans *= r.pow(q - 1); vector c1s(period); { mint2 t = len; rep(i, period) { mint1 c1 = mint1(10).pow(t.val()); // l+i, l+i+p, ..., l+i+(q-1)p // r^(q-1),r^(q-2), ..., 1 assert(r == 1); ll s = l + i; c1s[i] = mint1(2 * (l + i) + (q - 1) * period) * q / 2; c1s[i] *= c1; t = f(t); } } rep(i, period) { ans *= c0s[i]; ans += c1s[i]; } l += q * period; } rep(_, rem) tie(ans, len) = g(ans, len), l++; } return ans; } } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; cout << solve(n).val() << '\n'; }