#include <bits/stdc++.h>
using namespace std;
const long long N = 500 + 5;
const long long M = 1e6 + 5;
const long long maxn = 5e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long ksm(long long x, long long y = mod - 2, long long z = mod) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = (ret * x) % z;
    x = (x * x) % z;
    y >>= 1;
  }
  return ret;
}
long long inv[N], fac[N], ifc[N];
void gmax(long long &x, long long y) { x = max(x, y); }
void Init(long long n) {
  inv[1] = 1;
  for (register signed i = 2; i <= n; i++)
    inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  fac[0] = 1;
  for (register signed i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;
  ifc[0] = 1;
  for (register signed i = 1; i <= n; i++) ifc[i] = ifc[i - 1] * inv[i] % mod;
}
long long f[35][35][2];
long long n, ans;
signed main() {
  n = read();
  f[30][0][1] = 1;
  for (long long i = 30; i > 0; i--)
    for (long long j = 0; j <= 30; j++) {
      f[i - 1][j][0] += (1LL << j) * f[i][j][0] % mod;
      f[i - 1][j][0] %= mod;
      f[i - 1][j + 1][0] += f[i][j][0];
      f[i - 1][j + 1][0] %= mod;
      long long x = j ? (1 << (j - 1)) : 1, y = j ? (1 << (j - 1)) : 0;
      if (n >> (i - 1) & 1) {
        f[i - 1][j][0] += x * f[i][j][1] % mod, f[i - 1][j][0] %= mod;
        f[i - 1][j][1] += y * f[i][j][1] % mod, f[i - 1][j][1] %= mod;
        f[i - 1][j + 1][1] += f[i][j][1], f[i - 1][j + 1][1] %= mod;
      } else
        f[i - 1][j][1] += x * f[i][j][1] % mod, f[i - 1][j][1] %= mod;
    }
  for (long long i = 0; i <= 30; i++)
    ans += f[0][i][0], ans += f[0][i][1], ans %= mod;
  cout << ans << '\n';
}
