#include"bits/stdc++.h" //#include using namespace std; #define print(x) cout<> n; n += 1; string a="10"; rep(i, 1, n) { a += "0"; } dp[0][0][0][0] = 1; rep(i, 0, n)rep(j, 0, 2)rep(k, 0, 2)rep(l, 0, 3) { int lim = j ? 9 : a[i] - '0'; rep(d, 0, lim + 1) { dp[i + 1][j || d < lim][k || d == 3][(l + d) % 3] += dp[i][j][k][l]; } } unsigned long long ans = 0; rep(j, 0, 2)rep(k, 0, 2)rep(l, 0, 3) { if (k || l == 0) { ans += dp[n][j][k][l]; } } ans--; print(ans); return 0; }