#include <bits/stdc++.h>
using namespace std;
int f[1000005][20][2], cnt[20][2];
const int mod = 1e9 + 7;
int main() {
  int n, s, t;
  cin >> n;
  for (s = 1, t = 0; s <= n; s <<= 1, t++)
    ;
  s >>= 1;
  t--;
  f[1][t][0] = 1;
  if (s / 2 * 3 <= n) f[1][t - 1][1] = 1;
  for (int x = 0; x <= t; x++)
    for (int y = 0; y <= 1; y++) cnt[x][y] = n / (pow(2, x) * pow(3, y));
  for (int i = 2; i <= n; i++) {
    for (int x = 0; x <= t; x++)
      for (int y = 0; y <= 1; y++) {
        f[i][x][y] += (long long)f[i - 1][x][y] * (cnt[x][y] - i + 1) % mod;
        f[i][x][y] %= mod;
        if (x + 1 <= t)
          f[i][x][y] +=
              (long long)f[i - 1][x + 1][y] * (cnt[x][y] - cnt[x + 1][y]) % mod;
        f[i][x][y] %= mod;
        if (y + 1 <= 1)
          f[i][x][y] +=
              (long long)f[i - 1][x][y + 1] * (cnt[x][y] - cnt[x][y + 1]) % mod;
        f[i][x][y] %= mod;
      }
  }
  cout << f[n][0][0] << endl;
  return 0;
}
