#include <bits/stdc++.h>
using namespace std;
int n, dp[1000050][21][2], a;
long long pref[30][5], mod = (1000000000 + 7), fat[1000050];
int poww(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
int choose(int a, int b) {
  if (b > a) return 0;
  int A = fat[a] * poww(fat[b], mod - 2);
  A %= mod;
  A = (A * poww(fat[a - b], mod - 2)) % mod;
  return A;
}
int solve(int i, int p, int q) {
  if (q >= 2 or p > a) return 0;
  if (i == 1) {
    if (p == a and q == 0) return 1;
    if (p == a - 1 and q == 1 and (3 * (1 << p)) <= n) return 1;
    return 0;
  }
  if (dp[i][p][q] != -1) return dp[i][p][q];
  long long C =
      (1LL * solve(i - 1, p, q + 1) * (pref[p][q] - pref[p][q + 1])) % mod;
  long long A = (1ll * solve(i - 1, p, q) * (pref[p][q] - (i - 1))) % mod;
  long long B =
      (1LL * solve(i - 1, p + 1, q) * (pref[p][q] - pref[p + 1][q])) % mod;
  return dp[i][p][q] = (A + B + C) % mod;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) fat[i] = (i * fat[i - 1]) % mod;
  for (int a = 0; a <= 20; a++)
    for (int b = 0; b < 2; b++) pref[a][b] = (n / ((1 << a) * (b ? 3 : 1)));
  a = log2(n);
  cout << solve(n, 0, 0) << "\n";
}
