#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<void chmin(T&a,const T&b){if(a>b)a=b;} templatevoid chmax(T&a,const T&b){if(a f(ll N) { vector v; while (N != 0) { int r = (N % 5); if (r == 4) { v.push_back(-1); N += 4; } if (r == 3) { v.push_back(-2); N += 3; } if (r == 2) { v.push_back(2); N -= 2; } if (r == 1) { v.push_back(1); N -= 1; } if (r == 0) { v.push_back(0); } N /= 5; } reverse(ALL(v)); return v; } ll dp[30][2][2][200]; int main2() { CLR(dp, 0); ll N = nextLong(); auto v = f(N); // cout << "N=" << N << " : "; // pv(ALL(v)); reverse(ALL(v)); const int O = 100; const int n = v.size(); dp[n][0][0][O] = 1; for (int i = n-1; i >= 0; i--) { REP(isSmaller, 2) { REP(isPositive, 2) { for (int balance = -2*n; balance <= 2*n; balance++) { ll base = dp[i+1][isSmaller][isPositive][balance+O]; for (int x = -2; x <= 2; x++) { if (!isPositive && x < 0) continue; if (!isSmaller && x > v[i]) continue; int n_isSmaller = isSmaller || (v[i] > x); int n_isPositive = isPositive || (x > 0); int n_balance = balance + x; dp[i][n_isSmaller][n_isPositive][n_balance+O] += base; } } } } } ll ans = dp[0][0][1][O] + dp[0][1][1][O]; cout << ans << endl; return 0; } int main() { // for (int n = 1; n <= 20; n++) { // vector v = f(n); // cout << "n=" << n << ": "; // pv(ALL(v)); // } // { // auto v = f(1e18); // pv(ALL(v)); // int n = v.size(); // cout << (ll)pow(5, n) << endl; // } // return 0; #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }