#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n; cin >> n; string s; s += '1'; for (int i = 0; i < n; i++) s += '0'; vector dp(s.size() + 1, vector(2, vector(2, vector(3)))); dp[0][0][0][0] = 1; for (int i = 0; i < s.size(); i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) for (int l = 0; l < 3; l++) for (int m = 0; m < 10; m++) { if (!j and m > s[i] - '0') continue; int nj = j | (m != (s[i] - '0')); int nk = k | (m == 3); int nl = (l + m) % 3; dp[i + 1][nj][nk][nl] += dp[i][j][k][l]; } ll res = 0; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) { if (j == 1 or k == 0) res += dp[s.size()][i][j][k]; } cout << res - 1 << endl; return 0; }