#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; int N = S.size(); vector> dp(N + 1, vector(2, 0)); dp[0][0] = 1; for (int i = 0; i < N; i++) { int c = S[i] - '0'; for (int j = 0; j < 10; j++) { for (int k = 0; k < 2; k++) { if (k == 0 && j > c) continue; if (j % 3 != 0) continue; int nk = j < c ? 1 : k; dp[i + 1][nk] += dp[i][k]; } } } int res = dp[N][0] + dp[N][1] - 4; for (int i = 10; i < min(100, stoi(S) + 1); i++) { int x = i; while (x > 0 && x % 3 == 0) { x /= 10; } if (x != 0 && i % 3 == 0) res++; } cout << res << '\n'; return 0; }