#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6 + 1;
const int mod = 1e9 + 7;
int n;
int dp[nmax][20][2];
int32_t f(int x, int y) {
  int res = (y == 1) ? 3 : 1;
  return ((int)n / (res * (1 << x))) % mod;
}
int DP(int idx, int two, int thr) {
  if (idx > n) return 1;
  if (dp[idx][two][thr] != -1) return dp[idx][two][thr];
  long long cnt = f(two, thr);
  long long res = (cnt - idx + 1 > 0)
                      ? (DP(idx + 1, two, thr) * (cnt - idx + 1 + mod)) % mod
                      : 0;
  if (two && idx != 1)
    (res +=
     (DP(idx + 1, two - 1, thr) * (f(two - 1, thr) - cnt + mod)) % mod) %= mod;
  if (thr && idx != 1)
    (res +=
     (DP(idx + 1, two, thr - 1) * (f(two, thr - 1) - cnt + mod)) % mod) %= mod;
  return dp[idx][two][thr] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  int raise = log2(n);
  pair<int, int> a[2];
  a[0] = make_pair(raise, 0);
  if ((1 << (raise - 1)) * 3 <= n) {
    a[1] = make_pair(raise - 1, 1);
  }
  long long res = 0;
  for (int i = (int)0; i <= (int)1; i++)
    if (a[i].first + a[i].second) {
      for (int j = (int)0; j <= (int)n; j++)
        for (int k = (int)0; k <= (int)a[i].first; k++)
          for (int h = (int)0; h <= (int)a[i].second; h++) dp[j][k][h] = -1;
      (res += DP(1, a[i].first, a[i].second)) %= mod;
    }
  cout << res;
}
