#include <bits/stdc++.h>
using namespace std;
const int N = 40, P = 1e9 + 7;
inline long long read() {
  char c = getchar();
  long long x = 0, f = 1;
  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;
}
int n, f[N][N][2], a[N], len;
long long mi[N];
inline void mod(int &x) {
  if (x >= P) x -= P;
}
int dfs(int d, int j, int sky) {
  if (d == 0) return 1;
  if (f[d][j][sky] != -1) return f[d][j][sky];
  int &now = f[d][j][sky], lim = sky ? a[d] : 1;
  now = 0;
  if (!sky) {
    mod(now += mi[j] * dfs(d - 1, j, 0) % P);
    mod(now += dfs(d - 1, j + 1, 0) % P);
  } else {
    mod(now += (j == 0 ? 1 : mi[j - 1]) * dfs(d - 1, j, sky && 0 == lim) % P);
    if (a[d] == 1)
      mod(now += dfs(d - 1, j + 1, sky && 1 == lim) % P),
          mod(now +=
              (j == 0 ? 0 : mi[j - 1]) * dfs(d - 1, j, sky && 1 == lim) % P);
  }
  return now;
}
int main() {
  mi[0] = 1;
  for (int i = 1; i <= 30; i++) mi[i] = (mi[i - 1] << 1) % P;
  n = read();
  while (n) a[++len] = n & 1, n >>= 1;
  memset(f, -1, sizeof(f));
  printf("%d", dfs(len, 0, 1));
}
