#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e16;
long long dp[2][110][2][3][5][15];
int main() {
  string s;
  cin >> s;
  long long m = s.size();
  dp[0][0][0][0][0][0] = 1;
  for (long long id = 0; id < 2; id++) {
    for (long long i = 0; i < m; i++) {
      for (long long j = 0; j < 2; j++) {
        for (long long k3 = 0; k3 < 3; k3++) {
          for (long long k5 = 0; k5 < 5; k5++) {
            for (long long k15 = 0; k15 < 15; k15++) {
              long long lim = s[i] - '0';
              if (id) {
                lim = 9;
              }
              for (long long x = 0; x <= lim; x++) {
                dp[id || x < lim][i + 1][j || x == 3 || x == 5]
                  [(10 * k3 + x) % 3][(10 * k5 + x) % 5][(10 * k15 + x) % 15] +=
                    dp[id][i][j][k3][k5][k15];
                dp[id || x < lim][i + 1][j || x == 3 || x == 5]
                  [(10 * k3 + x) % 3][(10 * k5 + x) % 5][(10 * k15 + x) % 15] %=
                    mod;
              }
            }
          }
        }
      }
    }
  }
  long long ans = 0;
  for (long long id = 0; id < 2; id++) {
    for (long long k3 = 0; k3 < 3; k3++) {
      for (long long k5 = 0; k5 < 5; k5++) {
        for (long long k15 = 0; k15 < 15; k15++) {
          ans += dp[id][m][1][k3][k5][k15];
          ans %= mod;
        }
      }
    }
  }
  for (long long id = 0; id < 2; id++) {
    for (long long k3 = 0; k3 < 3; k3++) {
      for (long long k5 = 0; k5 < 5; k5++) {
        for (long long k15 = 0; k15 < 15; k15++) {
          if (k15 == 0) {
            continue;
          }
          if (k3 == 0 || k5 == 0) {
            ans += dp[id][m][0][k3][k5][k15];
            ans %= mod;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
