#include <bits/stdc++.h>
using namespace std;
int const MAX = 41;
int const MOD = 1e9 + 7;
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int mult(int a, int b) { return (long long)a * b % MOD; }
int k;
int d[MAX][MAX][2];
int p2[MAX];
void solve() {
  p2[0] = 1;
  for (int i = 1; i <= MAX - 1; i++) {
    p2[i] = add(p2[i - 1], p2[i - 1]);
  }
  vector<int> a;
  int x = k;
  while (x) {
    a.push_back((x & 1));
    x >>= 1;
  }
  reverse(a.begin(), a.end());
  for (int i = 0; i <= (int)a.size() - 1; i++) {
    if (i) {
      d[i][0][1] = 1;
    } else {
      d[i][0][0] = 1;
    }
  }
  for (int i = 0; i <= (int)a.size() - 1; i++) {
    for (int j = 0; j <= MAX - 2; j++) {
      for (int o = 0; o <= 1; o++) {
        if (!d[i][j][o]) continue;
        if (o || a[i]) {
          d[i + 1][j + 1][o] = add(d[i + 1][j + 1][o], d[i][j][o]);
        }
        if (j > 0) {
          int v1 = p2[j - 1];
          int v2 = d[i][j][o];
          int v = mult(v1, v2);
          int no = o;
          if (a[i]) no = 1;
          d[i + 1][j][no] = add(d[i + 1][j][no], v);
        }
        if (j > 0) {
          if (!o && a[i] == 0) continue;
          int v1 = p2[j - 1];
          int v2 = d[i][j][o];
          int v = mult(v1, v2);
          int no = o;
          d[i + 1][j][no] = add(d[i + 1][j][no], v);
        }
      }
    }
  }
  int ans = 1;
  for (int i = 0; i <= MAX - 1; i++) {
    for (int o = 0; o <= 1; o++) {
      ans = add(ans, d[(int)a.size()][i][o]);
    }
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d", &k);
  solve();
  return 0;
}
