#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long n;
long long f[35][35][2];
inline long long power(long long x, long long y) {
  if (y < 0) return 1;
  long long ans = 1;
  for (; y; y >>= 1) {
    if (y & 1) ans = ans * x % mod;
    x = x * x % mod;
  }
  return ans;
}
signed main() {
  n = read();
  f[31][0][1] = 1;
  for (long long i = 30; i >= 0; i--) {
    if (!((n >> i) & 1)) {
      for (long long j = 0; j <= 30 - i; j++) {
        f[i][j + 1][0] = (f[i][j + 1][0] + f[i + 1][j][0]) % mod;
        f[i][j][0] = (f[i][j][0] + f[i + 1][j][0] * power(2, j) % mod) % mod;
        f[i][j][1] =
            (f[i][j][1] + f[i + 1][j][1] * power(2, j - 1) % mod) % mod;
      }
    } else {
      for (long long j = 0; j <= 30 - i; j++) {
        f[i][j + 1][0] = (f[i][j + 1][0] + f[i + 1][j][0]) % mod;
        f[i][j][0] = (f[i][j][0] + f[i + 1][j][0] * power(2, j) % mod) % mod;
        f[i][j + 1][1] = (f[i][j + 1][1] + f[i + 1][j][1]) % mod;
        f[i][j][0] =
            (f[i][j][0] + f[i + 1][j][1] * power(2, j - 1) % mod) % mod;
        if (j)
          f[i][j][1] =
              (f[i][j][1] + f[i + 1][j][1] * power(2, j - 1) % mod) % mod;
      }
    }
  }
  long long ans = 1;
  for (long long i = 1; i <= 30; i++)
    ans = (ans + f[0][i][0] + f[0][i][1]) % mod;
  printf("%lld\n", ans);
  return 0;
}
