#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
int n;
long long cnt[4][20][20];
int dp[N][20][3];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int lg2 = log2(n);
  dp[1][lg2][0] = 1;
  if (pow(2, lg2 - 1) * 3 <= n) dp[1][lg2 - 1][1] = 1;
  for (int i = 0; i <= lg2; ++i)
    for (int j = 0; j <= 1; ++j) {
      int value = pow(2, i) * pow(3, j);
      int upper = n / value;
      cnt[0][i][j] = upper;
      for (int k = 1; k <= upper; ++k) {
        cnt[1][i][j] += (k % 2 != 0);
        cnt[2][i][j] += (k % 3 != 0);
      }
    }
  for (int i = 1; i <= n; ++i)
    for (int l2 = lg2; l2 >= 0; --l2)
      for (int l3 = 1; l3 >= 0; --l3)
        if (dp[i][l2][l3]) {
          if (cnt[0][l2][l3] > i)
            dp[i + 1][l2][l3] =
                (dp[i + 1][l2][l3] +
                 (long long)dp[i][l2][l3] * (cnt[0][l2][l3] - i) % MOD) %
                MOD;
          if (l2 > 0)
            dp[i + 1][l2 - 1][l3] =
                (dp[i + 1][l2 - 1][l3] +
                 (long long)dp[i][l2][l3] * cnt[1][l2 - 1][l3] % MOD) %
                MOD;
          if (l3 > 0)
            dp[i + 1][l2][l3 - 1] =
                (dp[i + 1][l2][l3 - 1] +
                 (long long)dp[i][l2][l3] * cnt[2][l2][l3 - 1] % MOD) %
                MOD;
        }
  cout << dp[n][0][0];
}
