#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
void bmax(int &a, int b) { a = (a > b) ? a : b; }
void bmin(int &a, int b) { a = (a < b) ? a : b; }
const int L = 1 << 20;
char buf[L], *p1, *p2;
int read() {
  int x = 0, w = 1;
  char ch = (p1 == p2 ? (p2 = buf + fread(p1 = buf, 1, L, stdin),
                         p1 == p2 ? EOF : *p1++)
                      : *p1++);
  while (ch > '9' || ch < '0') {
    if (ch == '-') w = -1;
    ch = (p1 == p2 ? (p2 = buf + fread(p1 = buf, 1, L, stdin),
                      p1 == p2 ? EOF : *p1++)
                   : *p1++);
  }
  while (ch <= '9' && ch >= '0')
    x = x * 10 + ch - '0',
    ch = (p1 == p2 ? (p2 = buf + fread(p1 = buf, 1, L, stdin),
                      p1 == p2 ? EOF : *p1++)
                   : *p1++);
  return x * w;
}
const int Mod = 1e9 + 7, K = 35;
int n, dp[K][K][2], powe[K];
void bmod(int &x) {
  x -= Mod;
  x += (x >> 31) & Mod;
}
int main() {
  n = read();
  dp[30][0][1] = 1;
  powe[0] = 1;
  for (int i = 1; i <= 30; i++) powe[i] = 2ll * powe[i - 1] % Mod;
  for (int i = 30; i >= 1; i--) {
    bool fl = (n >> (i - 1)) & 1;
    for (int j = 0; j <= 30; j++) {
      bmod(dp[i - 1][j + 1][0] += dp[i][j][0]);
      bmod(dp[i - 1][j][0] += 1ll * powe[j] * dp[i][j][0] % Mod);
      int tmp = (j == 0) ? 1 : powe[j - 1];
      if (!fl)
        bmod(dp[i - 1][j][1] += 1ll * tmp * dp[i][j][1] % Mod);
      else {
        bmod(dp[i - 1][j + 1][1] += dp[i][j][1]);
        bmod(dp[i - 1][j][0] += 1ll * dp[i][j][1] * tmp % Mod);
        int t2 = (j == 0) ? 0 : powe[j - 1];
        bmod(dp[i - 1][j][1] += 1ll * dp[i][j][1] * t2 % Mod);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 30; i++)
    bmod(ans += dp[0][i][0]), bmod(ans += dp[0][i][1]);
  printf("%d\n", ans);
  return 0;
}
