#include using namespace std; #define int long long #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; int n; int ans = 0; vector c; const int N = 101; int suff[N]; int dp[N][N]; void gen(int i, int bal, int sum) { if (sum + suff[i] < 1) return; if (sum - suff[i] >= 1 && sum + suff[i] <= n) { int r = (int)c.size() - i; ans += dp[r][abs(bal)]; return; } if (sum - suff[i] > n) return; if (i == c.size()) { if (bal == 0 && sum <= n) ++ans; return; } for (int x = -2; x <= 2; ++x) { gen(i + 1, bal + x, sum + c[i] * x); } } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif dp[0][0] = 1; for (int i = 1; i < N; ++i) { for (int j = 0; j < N; ++j) { for (int add = -2; add <= 2; ++add) { int to = abs(j+add); dp[i][j] += dp[i - 1][to]; } } } cin >> n; int cur = 1; while (1) { c.app(cur); if (cur > n) break; cur *= 5; } reverse(all(c)); suff[c.size()] = 0; for (int i = (int)c.size() - 1; i >= 0; --i) suff[i] = 2 * c[i] + suff[i+1]; //debug(c.size()); gen(0, 0, 0); cout << ans << endl; }