#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, K = 21, P = 1e9 + 7;
int n, m, f[N][K][2], _2[K];
void fix(int& x) { x = x < P ? x : x - P; }
int cnt(int i, int j) {
  int tmp = _2[i];
  if (j) tmp *= 3;
  return n / tmp;
}
signed main() {
  cin >> n;
  int lim = 1;
  while (lim <= n) _2[m] = lim, lim <<= 1, m++;
  m--;
  lim >>= 2;
  f[1][m][0] = 1;
  if (lim * 3 <= n) f[1][m - 1][1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = m; j >= 0; j--) {
      for (int k = 1; k >= 0; k--)
        if (f[i][j][k]) {
          if (j)
            fix(f[i + 1][j - 1][k] +=
                1ll * f[i][j][k] * (cnt(j - 1, k) - cnt(j, k) + P) % P);
          if (k)
            fix(f[i + 1][j][k - 1] +=
                1ll * f[i][j][k] * (cnt(j, k - 1) - cnt(j, k) + P) % P);
          fix(f[i + 1][j][k] += 1ll * f[i][j][k] * (cnt(j, k) - i + P) % P);
        }
    }
  }
  cout << f[n][0][0] << endl;
  return 0;
}
