// #include using namespace std; #define fi first #define se second #define all(x) x.begin(), x.end() #define lch (o << 1) #define rch (o << 1 | 1) typedef double db; typedef long long ll; typedef unsigned int ui; typedef pair pint; typedef tuple tint; const int N = 1e4 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; const int D2[] = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0}; const int D5[] = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0}; int f[N][2][2][3][3]; string s; int dfs(int o, int lim, int hasBegin, int f2, int f5) { if (o < 0) return f2 == 0 && f5 == 0; if (f[o][lim][hasBegin][f2][f5] != -1) return f[o][lim][hasBegin][f2][f5]; ll ans = 0; int upp = lim ? s[o] - '0' : 9; int low = hasBegin ? 1 : 0; for (int d = low; d <= upp; d++) { int d2 = D2[d]; int d5 = D5[d]; ans += dfs(o - 1, lim && (d == upp), (hasBegin || d > 0), max(f2 - d2, 0), max(f5 - d5, 0)); } ans = (ans % MOD + MOD) % MOD; return f[o][lim][hasBegin][f2][f5] = ans; } int main() { ios::sync_with_stdio(0); memset(f, -1, sizeof(f)); cin >> s; reverse(all(s)); int n = s.size(); ll ans = dfs(n - 1, 1, 0, 2, 2); cout << (ans % MOD + MOD) % MOD << endl; return 0; }