#include #include #include #include using namespace std; using ll = long long; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) templateusing priority_queue_rev = priority_queue, greater>; int main() { ll N; cin >> N; if (N < 1000000001) { cout << "0\n"; return 0; } int ans = 0; int n = N / 1000000001LL; // n以下の数字のうち回文である個数を求めれば良い priority_queue_rev>> q; rep(i, 10) q.emplace(1, make_pair(i, to_string(i))); q.emplace(1, make_pair(0, "")); while (!q.empty()) { auto [idx, e] = q.top(); q.pop(); auto [p, s] = e; if (p > n) break; if (s[0] != '0' && p != 0) { ++ans; } if (idx > 4) continue; rep(i, 10) { string s2 = to_string(i) + s + to_string(i); q.emplace(idx+1, make_pair(stoll(s2), s2)); } } cout << ans << endl; return 0; }