#include <bits/stdc++.h>
using namespace std;
const int N = 1000005, mod = 1e9 + 7;
int f[N][20][2], val[20][2];
int main() {
  int n;
  scanf("%d", &n);
  int x = 1, cnt = 0;
  while (x * 2 <= n) x *= 2, cnt++;
  f[1][cnt][0] = 1;
  if (x / 2 * 3 <= n) f[1][cnt - 1][1] = 1;
  val[0][0] = 1;
  val[0][1] = 3;
  for (int i = 1; i < 20; i++)
    for (int j = 0; j <= 1; j++) val[i][j] = val[i - 1][j] * 2;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j <= cnt; j++)
      for (int k = 0; k < 2; k++) {
        if (!f[i][j][k]) continue;
        f[i + 1][j][k] =
            (f[i + 1][j][k] + 1ll * f[i][j][k] * max(0, n / (val[j][k]) - i)) %
            mod;
        if (j) {
          f[i + 1][j - 1][k] =
              (f[i + 1][j - 1][k] +
               1ll * f[i][j][k] * (n / val[j - 1][k] - n / val[j][k])) %
              mod;
        }
        if (k) {
          f[i + 1][j][k - 1] =
              (f[i + 1][j][k - 1] +
               1ll * f[i][j][k] * (n / val[j][k - 1] - n / val[j][k])) %
              mod;
        }
      }
  }
  cout << f[n][0][0] << "\n";
}
