/* -*- coding: utf-8 -*- * * 491.cc: No.491 10^9+1ăšć›žæ–‡ - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ int ts[10], es[10]; /* main */ int main() { ts[0] = 1; for (int i = 1; i <= 9; i++) ts[i] = ts[i - 1] * 10; es[0] = 1; es[1] = es[2] = 9; for (int i = 3; i <= 9; i++) es[i] = es[i - 2] * 10; //for (int i = 0; i <= 9; i++) printf("es[%d]=%d\n", i, es[i]); ll n; cin >> n; int m = n / 1000000000; if (m > n % 1000000000) m--; //printf("m=%lld\n", m); int l = 0; for (int mm = m; mm > 0; l++, mm /= 10); //printf("l=%d\n", l); int sum = 0; for (int i = 1; i < l; i++) sum += es[i]; bool odd = ((l & 1) == 1); int l0 = (l + 1) / 2, l1 = l - l0; for (int a = ts[l0 - 1];; a++) { int c = a * ts[l1]; for (int b = (l0 > l1) ? a / 10 : a, t = ts[l1 - 1]; b > 0; b /= 10, t /= 10) c += (b % 10) * t; if (c > m) break; sum++; } printf("%d\n", sum); return 0; }