#include #include #include using namespace std; int main() { int N; cin >> N; if (N <= 99) { int cnt = 0; for (int i = 10; i <= N; ++i) { string str = to_string(i); bool ok = true; for (int j = 0; j < str.size(); ++j) { for (int k = 0; k < j; ++k) { if ((str[j] + str[k]) % 3 != 0) { ok = false; } } } if (ok) ++cnt; } cout << cnt << endl; } else { int cnt = 0; for (int i = 10; i <= 99; ++i) { string str = to_string(i); bool ok = true; for (int j = 0; j < str.size(); ++j) { for (int k = 0; k < j; ++k) { if ((str[j] + str[k]) % 3 != 0) { ok = false; } } } if (ok) ++cnt; } for (int i = 3; i <= 9; ++i) { int mul = 1; for (int j = 0; j < i; ++j) { mul *= 4; } for (int j = 0; j < mul; ++j) { string str; int x = j; for (int k = 0; k < i; ++k) { str += char((x % 4) * 3 + '0'); x /= 4; } if (str[0] != '0' && stoi(str) <= N) { ++cnt; } } } cout << cnt << endl; } return 0; }