// #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int solve(int cur,int n){ int res=0; if(cur>n)return 0; if(cur>100){res++;} if(cur)res+=solve(10*cur,n); res+=solve(10*cur+3,n)+solve(10*cur+6,n)+solve(10*cur+9,n); return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; int res=0; for(int i=12;i<=min(n,100);i+=3)res++; if(n<=100){ printf("%d\n",res); } else{ res+=solve(0,n); printf("%d\n",res); } }