#include #ifndef DUMP #define DUMP(...) (void)0 #endif using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; int res = 0; for (int bt = 0; bt < 1 << 18; ++bt) { string s; for (int i = 0; i < 9; ++i) s += "0369"[bt >> 2 * i & 3]; int x = stoi(s); res += 100 <= x and x <= n; } for (int i = 10; i < 100; ++i) if (i % 3 == 0) res += i <= n; cout << res << '\n'; }