#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; set s; function dfs = [&](ll x) { if (x > n) return; if (x >= 100) s.insert(x); if (x != 0) dfs(x * 10 + 0); dfs(x * 10 + 3); dfs(x * 10 + 6); dfs(x * 10 + 9); }; dfs(0); for (int x = 10; x <= min(n, 99); ++x) { if (((x / 10) + (x % 10)) % 3 == 0) s.insert(x); } //Debug(s); cout << s.size() << '\n'; return 0; }