#include <bits/stdc++.h>
using namespace std;
void enable_comma() {}
string tostring(char c) {
  string s = "";
  s += c;
  return s;
}
string tostring(string s) { return "\"" + s + "\""; }
string tostring(const char *c) { return tostring((string)c); }
string tostring(long long x) {
  if (x < 0) return "-" + tostring(-x);
  if (x > 9)
    return tostring(x / 10) + tostring(char('0' + x % 10));
  else
    return tostring(char('0' + x));
}
string tostring(int x) { return tostring((long long)x); }
string tostring(unsigned long long x) {
  if (x > 9)
    return tostring((long long)(x / 10)) + tostring(char('0' + x % 10));
  else
    return tostring(char('0' + x));
}
string tostring(unsigned x) { return tostring((long long)x); }
string tostring(double x) {
  static char res[114];
  sprintf(res, "%lf", x);
  string s = tostring(res);
  return s.substr(1, (int)s.size() - 2);
}
string tostring(long double x) { return tostring((double)x); }
template <class A, class B>
string tostring(pair<A, B> p) {
  return "(" + tostring(p.first) + "," + tostring(p.second) + ")";
}
template <class T>
string tostring(T v) {
  string res = "";
  for (auto p : v) res += (res.size() ? "," : "{") + tostring(p);
  return res.size() ? res + "}" : "{}";
}
template <class A>
string tostring(A *a, int L, int R) {
  return tostring(vector<A>(a + L, a + R + 1));
};
template <class A>
string tostring(A a, int L, int R) {
  return tostring(a.data(), L, R);
}
string tostrings() { return ""; }
template <typename Head, typename... Tail>
string tostrings(Head H, Tail... T) {
  return tostring(H) + " " + tostrings(T...);
}
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
template <class T>
void ckmax(T &x, const T y) {
  if (x < y) x = y;
}
template <class T>
void ckmin(T &x, const T y) {
  if (x > y) x = y;
}
const int mod = 1e9 + 7;
int Pow(int x, long long y) {
  y = (y % (mod - 1) + (mod - 1)) % (mod - 1);
  int ans = 1;
  for (; y; y >>= 1, x = (long long)x * x % mod)
    if (y & 1) ans = (long long)ans * x % mod;
  return ans;
}
void Add(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
void Del(int &x, int y) {
  if ((x -= y) < 0) x += mod;
}
int Add(int x) { return x >= mod ? x - mod : x; }
int Del(int x) { return x < 0 ? x + mod : x; }
int md(long long x) { return (x % mod + mod) % mod; }
const int N = 30;
int k;
int dp[N][N][2];
int DP(int d, int c, int f) {
  if (d < 0) return 1;
  int &res = dp[d][c][f];
  if (res != -1) return res;
  res = 0;
  if (f) {
    {
      if (!c) {
        Add(res, DP(d - 1, c, ~k >> d & 1));
      } else {
        if (k >> d & 1) {
          Add(res, (long long)(DP(d - 1, c, 0) + DP(d - 1, c, 1)) *
                       (1 << (c - 1)) % mod);
        } else {
          Add(res, (long long)DP(d - 1, c, 1) * (1 << (c - 1)) % mod);
        }
      }
    }
    if (k >> d & 1) {
      Add(res, (long long)DP(d - 1, c + 1, 1) % mod);
    }
  } else {
    Add(res, (long long)DP(d - 1, c, 0) * (1 << c) % mod);
    Add(res, (long long)DP(d - 1, c + 1, 0) % mod);
  }
  return res;
}
void solve() {
  k = read();
  memset(dp, -1, sizeof dp);
  cout << DP(29, 0, 1) << endl;
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
