#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  bool f = true;
  long long x = 0;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = false;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  if (f) return x;
  return ~(--x);
}
inline int read(char *s) {
  int len = 0;
  register char ch = getchar();
  while (ch == ' ' || ch == '\n') ch = getchar();
  while (ch != ' ' && ch != '\n' && ch != EOF) s[++len] = ch, ch = getchar();
  return len;
}
inline void write(const long long &x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void print(const long long &x) {
  x < 0 ? putchar('-'), write(~(x - 1)) : write(x);
  putchar('\n');
}
inline long long max(const long long &a, const long long &b) {
  return a > b ? a : b;
}
inline long long min(const long long &a, const long long &b) {
  return a < b ? a : b;
}
const long long mod = 1e9 + 7;
long long odd[64], even[64], base[64], f[32][32][2], n;
int main() {
  n = read();
  base[0] = 1, odd[0] = 0, even[0] = 1;
  for (register int i = 1; i < 64; ++i)
    base[i] = base[i - 1] << 1, even[i] = odd[i] = base[i - 1] % mod;
  f[30][0][1] = 1;
  for (register int i = 30; i; --i) {
    for (register int j = 0; j <= 30; ++j) {
      f[i - 1][j][0] = (f[i - 1][j][0] + f[i][j][0] * base[j] % mod) % mod;
      f[i - 1][j + 1][0] = (f[i - 1][j + 1][0] + f[i][j][0]) % mod;
      if (n & base[i - 1]) {
        f[i - 1][j + 1][1] = (f[i - 1][j + 1][1] + f[i][j][1]) % mod;
        f[i - 1][j][0] = (f[i - 1][j][0] + f[i][j][1] * even[j] % mod) % mod;
        f[i - 1][j][1] = (f[i - 1][j][1] + f[i][j][1] * odd[j] % mod) % mod;
      } else
        f[i - 1][j][1] = (f[i - 1][j][1] + f[i][j][1] * even[j] % mod) % mod;
    }
  }
  long long ans = 0;
  for (register int i = 0; i <= 30; ++i)
    ans = (ans + f[0][i][0] + f[0][i][1]) % mod;
  print(ans);
  return 0;
}
