#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
using namespace std;
template <class T>
inline void read(T &x) {
  int f = 0, ch = 0;
  x = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = 1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  if (f) x = -x;
}
const long long Mod = 1e9 + 7;
long long s[55], f[55][55][2], len, ans;
inline void up(long long &x, long long y) { x = (x + y % Mod) % Mod; }
signed main() {
  long long x;
  read(x);
  if (!x) s[++len] = 0;
  while (x) s[++len] = x % 2, x /= 2;
  reverse(s + 1, s + len + 1);
  f[0][0][1] = 1;
  for (long long i = 1; i <= len; i++)
    for (long long j = 0; j <= len; j++) {
      if (j) up(f[i][j][0], f[i - 1][j - 1][0]);
      up(f[i][j][0], f[i - 1][j][0] * (1ll << j));
      long long x = (j ? (1ll << j - 1) : 1) % Mod;
      long long y = (j ? (1ll << j - 1) : 0) % Mod;
      if (s[i] == 0)
        up(f[i][j][1], f[i - 1][j][1] * x);
      else {
        if (j) up(f[i][j][1], f[i - 1][j - 1][1]);
        up(f[i][j][1], f[i - 1][j][1] * y);
        up(f[i][j][0], f[i - 1][j][1] * x);
      }
    }
  for (long long i = 0; i <= len; i++)
    up(ans, f[len][i][0]), up(ans, f[len][i][1]);
  cout << ans;
  return 0;
}
