/** * @FileName a.cpp * @Author kanpurin * @Created 2020.08.22 17:48:54 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; bool ok(int x) { if (x % 3 != 0) return false; vector v; while(x) { v.push_back(x % 10); x /= 10; } for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { if ((v[i] + v[j]) % 3 != 0) { return false; } } } return true; } int n,cnt; void dfs(int keta, vector &v) { if (keta == 9) { int p = 0; int k = 1; for (int i = 0; i < 9; i++) { p += k * v[i]; k *= 10; } if (100 <= p && p <= n) { cnt++; } } else { for (int i = 0; i <= 9; i+=3) { v.push_back(i); dfs(keta+1,v); v.pop_back(); } } } int main() { cin >> n; for (int i = 12; i <= min(99,n); i++) { if (ok(i)) cnt++; } vector v; dfs(0,v); cout << cnt << endl; return 0; }