#assert from itertools import product N = input() if not(1<=int(N)<=10**10000): print('error') mod=10**9+7 def count(a): n = len(a) dp=[[[[[[0] * 2 for i in range(2)] for j in range(3)] for k in range(3)] for l in range(2)] for l in range(n+1)] dp[0][0][0][0][1][0] = 1 for i, less, divcnt5, divcnt2, leading0, hasin0 in product(range(n), (0,1), range(3), range(3), (0,1), (0,1)): max_d = 9 if less else int(a[i]) for d in range(max_d+1): less_ = less or d < max_d #5で割れる回数(0,1,2回以上) divcnt5_ = min(2,divcnt5+(d==5)) #(0を除いて)2で割れる回数(0,1,2回以上) if d==4 or d==8: divcnt2_=2 elif d==2 or d==6: divcnt2_=min(2,divcnt2+1) else: divcnt2_ = divcnt2 leading0_ = leading0 and d == 0 if leading0: #leading0がtrueである限り、hasin0はfalseですが、理解しやすく書くとこうなります hasin0_ = hasin0 else: hasin0_ = hasin0 or d==0 dp[i + 1][less_][divcnt5_][divcnt2_][leading0_][hasin0_] = (dp[i + 1][less_][divcnt5_][divcnt2_][leading0_][hasin0_] + dp[i][less][divcnt5][divcnt2][leading0][hasin0]) % mod #合致するものを合算(不要なのも混じっていますが) ret = 0 for less, leading0 in product((0,1), (0,1)): ret = (ret + dp[n][less][2][2][leading0][0]) % mod return ret print(count(N))