#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e6 + 10;
int Vp[MAX];
const int L = 60;
int Q[L][2];
int Qt[L];
int Sum[L];
int Tot[L];
int Acc[L];
ll F[MAX];
const int MOD = 1e9 + 7;
inline ll prod(ll a, ll b) { return (a * b) % MOD; }
ll inv(ll x) {
  ll res = 1;
  int e = MOD - 2;
  while (e) {
    if (e % 2) res = prod(res, x);
    x = prod(x, x);
    e /= 2;
  }
  return res;
}
ll bino(ll x, ll y) {
  ll res = F[x];
  res = prod(res, y + 1);
  res = prod(res, inv(F[x - y]));
  return res;
}
void calc(int x) {
  int y = x;
  while (y % 2 == 0) {
    y /= 2;
    Vp[x]++;
  }
}
int main() {
  F[0] = 1;
  for (int i = 1; i < MAX; i++) {
    F[i] = prod(F[i - 1], i);
  }
  int n;
  scanf("%d", &n);
  int cnt = 0;
  int pot = 1;
  while (2 * pot <= n) {
    pot *= 2;
    cnt++;
  }
  for (int i = 1; i <= n; i++) {
    calc(i);
    Qt[Vp[i]]++;
    if (i % 3 == 0)
      Q[Vp[i]][1]++;
    else
      Q[Vp[i]][0]++;
  }
  for (int i = L - 2; i >= 0; i--) {
    Acc[i] = Acc[i + 1] + Q[i][1];
    Sum[i] = Sum[i + 1] + Q[i][0];
    Tot[i] = Tot[i + 1] + Qt[i];
  }
  ll res1 = 1;
  int totis = n;
  for (int i = cnt; i >= 0; i--) {
    res1 = prod(res1, bino(totis - 1, Qt[i] - 1));
    totis -= Qt[i];
  }
  int maxi = cnt - 1;
  ll res2 = 0;
  if ((pot / 2) * 3 <= n) {
    ll res;
    for (int i = maxi + 1; i >= 1; i--) {
      if (i == maxi + 1) {
        int tot = n;
        res = bino(tot - 1, Q[maxi][1] - 1);
        tot -= Q[maxi][1];
        res = prod(res, bino(tot - 1, Sum[maxi] - 1));
        tot -= Sum[maxi];
        for (int j = maxi - 1; j >= 0; j--) {
          res = prod(res, bino(tot - 1, Qt[j] - 1));
          tot -= Qt[j];
        }
        res2 = (res2 + res) % MOD;
        continue;
      }
      ll b1 = bino(n - Acc[i] - 1, Sum[i] - 1);
      ll b2 = bino(n - Tot[i] - 1, Qt[i - 1] - 1);
      ll b3 = bino(n - Acc[i] - 1, Q[i - 1][1] - 1);
      ll b4 = bino(n - Acc[i - 1] - 1, Sum[i - 1] - 1);
      res = prod(res, b3);
      res = prod(res, b4);
      ll cancel = prod(b1, b2);
      res = prod(res, inv(cancel));
      res2 = (res2 + res) % MOD;
    }
  }
  ll fres = (res1 + res2) % MOD;
  printf("%lld\n", fres);
}
