#include using namespace std; using ll = long long; constexpr char newl = '\n'; constexpr int geta = 150; vector convert(ll n) { vector res; bool f = false; while (n > 0) { int d = n % 5 + f; f = (d > 2); res.push_back((d <= 2 ? d : d - 5)); n /= 5; } if (f) res.push_back(1); reverse(res.begin(), res.end()); return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector v = convert(n); int sz = v.size(); /* for (int i = 0; i < sz; i++) { cerr << v[i] << " "; } cerr << endl;//*/ vector< vector< vector > > dp(2, vector< vector >(2, vector(geta * 2 + 1, 0))); dp[false][false][geta] = 1; for (int i = 0; i < sz; i++) { vector< vector< vector > > ndp(2, vector< vector >(2, vector(geta * 2 + 1, 0))); for (int j = -geta; j <= geta; j++) { if (dp[false][false][j + geta]) { //cerr << i << " " << false << " " << false << " " << j << " " << dp[false][false][j + geta] << newl; for (int k = 0; k <= v[i]; k++) { if (j + k <= geta) ndp[k < v[i]][k > 0][j + geta + k] += dp[false][false][j + geta]; } } if (dp[false][true][j + geta]) { //cerr << i << " " << false << " " << true << " " << j << " " << dp[false][true][j + geta] << newl; for (int k = -2; k <= v[i]; k++) { if (j + k >= -geta && j + k <= geta) ndp[k < v[i]][true][j + geta + k] += dp[false][true][j + geta]; } } if (dp[true][false][j + geta]) { //cerr << i << " " << true << " " << false << " " << j << " " << dp[true][false][j + geta] << newl; ndp[true][false][j + geta] += dp[true][false][j + geta]; if (j + 1 <= geta) ndp[true][true][j + geta + 1] += dp[true][false][j + geta]; if (j + 2 <= geta) ndp[true][true][j + geta + 2] += dp[true][false][j + geta]; } if (dp[true][true][j + geta]) { //cerr << i << " " << true << " " << true << " " << j << " " << dp[true][true][j + geta] << newl; if (j - 1 >= -geta) ndp[true][true][j + geta - 1] += dp[true][true][j + geta]; if (j - 2 >= -geta) ndp[true][true][j + geta - 2] += dp[true][true][j + geta]; ndp[true][true][j + geta] += dp[true][true][j + geta]; if (j + 1 <= geta) ndp[true][true][j + geta + 1] += dp[true][true][j + geta]; if (j + 2 <= geta) ndp[true][true][j + geta + 2] += dp[true][true][j + geta]; } } dp = move(ndp); } /* int i = sz; for (int j = -geta; j <= geta; j++) { if (dp[false][false][j + geta]) { cerr << i << " " << false << " " << false << " " << j << " " << dp[false][false][j + geta] << newl; } if (dp[false][true][j + geta]) { cerr << i << " " << false << " " << true << " " << j << " " << dp[false][true][j + geta] << newl; } if (dp[true][false][j + geta]) { cerr << i << " " << true << " " << false << " " << j << " " << dp[true][false][j + geta] << newl; } if (dp[true][true][j + geta]) { cerr << i << " " << true << " " << true << " " << j << " " << dp[true][true][j + geta] << newl; } }//*/ ll ans = dp[false][true][geta] + dp[true][true][geta]; cout << ans << newl; return 0; }