#include #include #include #include using ll = long long; using mint = atcoder::modint998244353; using mat = std::array, 3>; mat mul(mat a, mat b) { mat c; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { c[i][k] += a[i][j] * b[j][k]; } } } return c; } mat id() { mat a; for (int i = 0; i < 3; i++) a[i][i] = 1; return a; } mat pow(mat a, ll e) { mat r = id(); while (e) { if (e & 1) r = mul(r, a); a = mul(a, a); e >>= 1; } return r; } ll pow10(int e) { ll ret = 1; while (e--) ret *= 10; return ret; } int main() { const int tail = 23; const int period = 24; ll n; std::cin >> n; mint ans = 0; mint b = 1; for (int d = 1; pow10(d - 1) <= n; d++) { const mint m = mint(10).pow(d); const ll st = pow10(d - 1); const ll en = std::min(pow10(d), n + 1); ll i = st; while (i < en && (i - st < tail || (en - i) % period != 0)) { ans = (ans * m + i) * b + ans; b *= m * b; i++; } if (i == en) continue; const mint c = b; mat a = id(); for (int k = 0; k < period; k++) { a = mul({{{m * b + 1, b, 0}, {0, 1, 1}, {0, 0, 1}}}, a); b *= m * b; } assert(b == c); const mat res = pow(a, (en - i) / period); ans = res[0][0] * ans + res[0][1] * i + res[0][2]; } std::cout << ans.val() << "\n"; return 0; }