#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n; n/=Int(1e9+1); set ss; for(Int i=1;i<100000;i++){ string s=to_string(i); string t(s); reverse(t.begin(),t.end()); { Int x=stoll(s+t); if(x<=n) ss.emplace(x); } if(s.back()==t.front()){ s.pop_back(); Int x=stoll(s+t); if(x<=n) ss.emplace(x); } } cout<