#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 5;
const int LOG = 21;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long sq(long long x) { return (x * x) % MOD; }
long long modP(long long a, long long b) {
  return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);
}
int n;
int dp[maxN][LOG][2];
long long num(int a, int b) { return (n / ((1 << a) * (b ? 3 : 1))); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d", &n);
  memset(dp, 0, sizeof dp);
  int pw = 31 - __builtin_clz(n);
  dp[1][pw][0] = 1;
  if (3 * (1 << (pw - 1)) <= n) dp[1][pw - 1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= pw; j++) {
      for (int k = 0; k < 2; k++) {
        dp[i][j][k] =
            (dp[i][j][k] + 1ll * dp[i - 1][j][k] * (MOD + num(j, k) - i + 1) +
             MOD) %
            MOD;
        if (j != LOG - 1) {
          dp[i][j][k] =
              (dp[i][j][k] +
               1ll * dp[i - 1][j + 1][k] * (MOD + num(j, k) - num(j + 1, k)) +
               MOD) %
              MOD;
        }
        if (k == 0) {
          dp[i][j][k] =
              (dp[i][j][k] +
               1ll * dp[i - 1][j][k + 1] * (MOD + num(j, k) - num(j, k + 1)) +
               MOD) %
              MOD;
        }
      }
    }
  }
  printf("%d", dp[n][0][0]);
  return 0;
}
