#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """123456 # """ # sys.stdin = io.StringIO(_INPUT) INF = 10**10 MOD = 1000000007 N = input() L = len(N) dp = [[[[[0, 0], [0, 0]] for _ in range(3)] for _ in range(3)] for _ in range(L+1)] dp[0][0][0][1][0] = 1 for i in range(L): for n2 in range(3): for n5 in range(3): for lzero in [0, 1]: for less in [0, 1]: if lzero: dp[i+1][0][0][1][1] = (dp[i+1][0][0][1][1] + dp[i][n2][n5][lzero][less]) % MOD for k in range(1, 10 if less else int(N[i])+1): less_1 = less | (k < int(N[i])) n2_1 = n2 n5_1 = n5 if k == 2: n2_1 = min(n2+1, 2) elif k == 4: n2_1 = 2 elif k == 5: n5_1 = min(n5+1, 2) elif k == 6: n2_1 = min(n2+1, 2) elif k == 8: n2_1 = 2 dp[i+1][n2_1][n5_1][0][less_1] = (dp[i+1][n2_1][n5_1][0][less_1] + dp[i][n2][n5][lzero][less]) % MOD ans = sum(dp[L][2][2][0]) % MOD print(ans)