#include <bits/stdc++.h>
using namespace std;
inline void open(const char *s) {}
inline int rd() {
  static int x, f;
  x = 0;
  f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return f > 0 ? x : -x;
}
const int N = 1000010, mod = 1000000007;
int n, f[21][2], dp[N][21][2];
inline int pls(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int upd(int &a, int b) { return a = pls(a, b); }
inline int mns(int a, int b) { return a < b ? a - b + mod : a - b; }
inline int mul(int a, int b) { return (long long)a * b % mod; }
int main() {
  n = rd();
  int m = 0, hh = 1, h = 0;
  while (hh <= n) hh <<= 1, ++m;
  hh /= 2, --m;
  if (hh / 2 * 3 <= n) h = 1;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= h; j++) f[i][j] = n / ((1 << i) * (j ? 3 : 1));
  dp[1][m][0] = 1;
  if (h) dp[1][m - 1][1] = 1;
  for (int i = 1; i <= n - 1; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= h; k++)
        if (dp[i][j][k]) {
          int tmp = dp[i][j][k];
          if (f[j][k] > i) upd(dp[i + 1][j][k], mul(tmp, f[j][k] - i));
          if (j) upd(dp[i + 1][j - 1][k], mul(tmp, f[j - 1][k] - f[j][k]));
          if (k) upd(dp[i + 1][j][k - 1], mul(tmp, f[j][k - 1] - f[j][k]));
        }
  cout << dp[n][0][0];
  return 0;
}
