#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 9;
int dp[maxn][23][2];
long long n;
int main() {
  cin >> n;
  int x = 20;
  while (n / (1 << x) == 0) x--;
  int y = n / (1 << x - 1) / 3;
  dp[1][x][0] = 1;
  if (y) dp[1][x - 1][y] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 0; j <= x; j++) {
      dp[i][j][0] =
          (1ll * dp[i - 1][j][0] * (n / (1 << j) - i + 1) +
           1ll * dp[i - 1][j][1] * (n / (1 << j) - n / (1 << j) / 3) +
           1ll * dp[i - 1][j + 1][0] * (n / (1 << j) - n / (1 << j + 1))) %
          mod;
      dp[i][j][1] = (1ll * dp[i - 1][j][1] * (n / (1 << j) / 3 - i + 1) +
                     1ll * dp[i - 1][j + 1][1] *
                         (n / (1 << j) / 3 - n / (1 << j + 1) / 3)) %
                    mod;
    }
  cout << dp[n][0][0] << endl;
  return 0;
}
