#!/usr/bin/python3 def conv(x, base): v = [] while x != 0: rem = x % base if rem > base // 2: rem -= base v.append(rem) x -= rem x //= base v.reverse() return v def f(x): a = conv(x, 5) n = len(a) dp = [[[[0] * (n+1) for _ in range(n+1)] for _ in range(2)] for _ in range(2)] dp[0][0][0][0] = 1 for i in range(n): ndp = [[[[0] * (n+1) for _ in range(n+1)] for _ in range(2)] for _ in range(2)] for less in range(2): for nuke0 in range(2): for cntM in range(n+1): for cntP in range(n+1): if dp[less][nuke0][cntM][cntP] == 0: continue l = -2 if nuke0 else 0 r = 2 if less else a[i] for d in range(l, r+1): nless = less or d < a[i] n_nuke0 = nuke0 or d > 0 ncntM = cntM + (-d if d < 0 else 0) ncntP = cntP + ( d if d > 0 else 0) if ncntM > n or ncntP > n: continue ndp[nless][n_nuke0][ncntM][ncntP] += dp[less][nuke0][cntM][cntP] dp = ndp res = 0 for less in range(2): for cnt in range(1, n+1): res += dp[less][1][cnt][cnt] return res ### N = int(input()) assert 1 <= N <= 10**18 res = f(N) print(res)