#include #include #include #include #include using namespace std; using i64 = int64_t; vector conv(i64 x, int base) { assert(base % 2 == 1); vector v; while(x != 0) { int rem = static_cast(x % base); if(rem > base / 2) { rem -= base; } v.push_back(rem); x -= rem; assert(x % base == 0); x /= base; } reverse(v.begin(), v.end()); return v; } // 上から i64 f(i64 x) { vector a = conv(x, 5); int n = static_cast(a.size()); // dp[未満フラグ][先行ゼロを抜けたか][荷物側(桁の数字が負)の分銅数][反対側(桁の数字が正)の分銅数] := パターン数 vector>>> dp(2, vector>>(2, vector>(n+1, vector(n+1, 0)))); dp[0][0][0][0] = 1; for(int i=0; i>>> ndp(2, vector>>(2, vector>(n+1, vector(n+1, 0)))); for(int less=0; less<2; ++less) { for(int nuke0=0; nuke0<2; ++nuke0) { for(int cntM=0; cntM<=n; ++cntM) { for(int cntP=0; cntP<=n; ++cntP) { if(!dp[less][nuke0][cntM][cntP]) { continue; } // [l, r] int l = nuke0 ? -2 : 0, r = less ? 2 : a[i]; for(int d=l; d<=r; ++d) { int nless = less || d < a[i], n_nuke0 = nuke0 || d > 0, ncntM = cntM + (d < 0 ? -d : 0), ncntP = cntP + (d > 0 ? d : 0); if(ncntM > n) { continue; } if(ncntP > n) { continue; } ndp[nless][n_nuke0][ncntM][ncntP] += dp[less][nuke0][cntM][cntP]; } } } } } dp = ndp; } i64 res = 0; for(int less=0; less<2; ++less) { for(int cnt=1; cnt<=n; ++cnt) { res += dp[less][1][cnt][cnt]; } } return res; } int main(void) { i64 N; scanf("%ld", &N); assert(1 <= N && N <= static_cast(powl(10, 18))); i64 res = f(N); printf("%ld\n", res); return 0; }