#include using namespace std; int main(){ int n; cin >> n; int lim = min(100,n); vector d; int count =0; bool last=true; while(n>0){ d.push_back(n%10); n /= 10; last &= d.back()%3==0; } //for(auto& i : d) cout << i << ' ' ; cout << endl; bool dig = false; for(auto it = d.rbegin(); it != d.rend(); ++it){ count *=4; if(!dig)count += (*it)/3; else count +=3; if(dig && (*it)==0) dig = true; else if((*it)%3!=0) dig = true; else dig = false; } count -= 3; //cout << count << endl; for(int i=10; i<=lim; i++) if(i%3==0 && i%10%3 !=0) count ++; if(last) count ++; cout << count << endl; }