#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define sz(x) ((ll)(x).size()) #define ceil(x, y) (((x)+(y)-1) / (y)) #define all(x) (x).begin(),(x).end() #define outl(...) dump_func(__VA_ARGS__) #define inf 1e18 #define mod 1000000007 using namespace std; typedef long long llint; typedef long long ll; typedef pair P; bool exceed(ll x, ll y, ll m){return x >= m / y + 1;} template ostream& operator << (ostream& os, vector& vec) { for(int i = 0; i ostream& operator << (ostream& os, pair& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template ostream& operator << (ostream& os, map& map_var) { for(typename map::iterator itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ","; itr--; } return os; } template ostream& operator << (ostream& os, set& set_var) { for(typename set::iterator itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << " "; itr--; } return os; } void dump_func() {cout << endl;} template void dump_func(Head &&head, Tail &&... tail) { cout << head; if(sizeof...(Tail) > 0) cout << " "; dump_func(std::move(tail)...); } string s; ll dp[10005][2][3][3]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> s; ll n = sz(s); reverse(all(s)); dp[n][0][0][0] = 1; rep(i, 1, n-1) dp[i][1][0][0] = 1; for(int i = n; i >= 1; i--){ ll c = s[i-1] - '0'; rep(j, 0, 1){ rep(k, 0, 2){ rep(l, 0, 2){ rep(m, 1, 9){ ll nj = j, nk = k, nl = l; if(j == 0 && c < m) continue; if(c > m) nj = 1; if(m % 4 == 0) nk += 2; else if(m % 2 == 0) nk++; if(m % 5 == 0) nl++; chmin(nk, 2LL), chmin(nl, 2LL); (dp[i-1][nj][nk][nl] += dp[i][j][k][l]) %= mod; } } } } } ll ans = dp[0][0][2][2] + dp[0][1][2][2]; outl(ans); return 0; }