#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pi = pair<int, int>;
using ll = long long int;
template <typename T1, typename T2, typename T3>
T1 modpow(T1 _a, T2 p, T3 mod) {
  assert(p >= 0);
  ll ret = 1, a = _a;
  if (a < 0) {
    a %= mod;
    a += mod;
  }
  if (a >= mod) {
    a %= mod;
  }
  for (; p > 0; p /= 2) {
    if (p & 1) ret = ret * a % mod;
    a = a * a % mod;
  }
  return ret;
}
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr auto PI = 3.14159265358979323846L;
constexpr auto oo = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr int mx_n = 31;
int dp[mx_n][2][mx_n], bits[mx_n];
int brute(int n) {
  int ret = 0;
  for (int mask = ((0)), _mask = (((1 << (n + 1))) - 1); mask <= _mask; ++mask)
    if ((((mask) >> 0) & 1)) {
      vi pos;
      for (int i = ((0)), _i = ((n + 1) - 1); i <= _i; ++i)
        if ((((mask) >> i) & 1)) pos.push_back(i);
      bool ok = true;
      for (int i = ((1)), _i = (((int((pos).size()))) - 1); i <= _i; ++i) {
        if (!ok) break;
        for (int j = ((i + 1)), _j = (((int((pos).size()))) - 1); j <= _j;
             ++j) {
          int cur = (pos[i] ^ pos[j]);
          if (!(((mask) >> cur) & 1)) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        ;
        ++ret;
      }
    }
  return ret;
}
int solve(int i, int eq, int v) {
  if (i == -1) {
    ;
    return 1;
  }
  int& ret = dp[i][eq][v];
  if (ret != -1) return ret;
  if (!eq || bits[i]) {
    ret = solve(i - 1, (eq && bits[i] == 1), v + 1);
    if (v == 0) {
      ret = (ret + solve(i - 1, (eq && bits[i] == 0), v)) % mod;
    } else {
      ret = (ret +
             (1ll << (v - 1)) % mod * solve(i - 1, (eq && bits[i] == 0), v)) %
            mod;
      ret = (ret +
             (1ll << (v - 1)) % mod * solve(i - 1, (eq && bits[i] == 1), v)) %
            mod;
    }
  } else {
    if (v) {
      ret =
          (1ll << (v - 1)) % mod * solve(i - 1, (eq && bits[i] == 0), v) % mod;
    } else {
      ret = solve(i - 1, (eq && bits[i] == 0), v);
    }
  };
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = ((0)), _i = ((mx_n)-1); i <= _i; ++i)
    if ((((n) >> i) & 1)) bits[i] = 1;
  memset(dp, -1, sizeof(dp));
  int ans = solve(mx_n - 1, 1, 0) % mod;
  cout << ans << endl;
  return 0;
}
