#include <bits/stdc++.h>
using namespace std;
const long long N = 100;
long long n, a[N], len, dp[N][N][2][2], z[N];
inline void add(long long &a, long long b) {
  a = ((a + b >= 1000000007) ? a + b - 1000000007 : a + b);
}
inline void del(long long &a, long long b) {
  a = ((a - b < 0) ? a - b + 1000000007 : a - b);
}
inline void mul(long long &a, long long b) { a = a * b % 1000000007; }
inline long long m_pow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) mul(ans, a);
    b >>= 1;
    mul(a, a);
  }
  return ans;
}
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
long long dfs(long long x, long long s, long long lim, long long lead) {
  if (dp[x][s][lim][lead]) return dp[x][s][lim][lead];
  if (x == len + 1) return (s > 0);
  long long up = ((lim) ? a[x] : 1);
  for (long long i = 0; i <= up; i++) {
    if (i == 0) {
      if (!s)
        add(dp[x][s][lim][lead],
            dfs(x + 1, s, lim & (i == up), lead & (i == 0)) % 1000000007);
      else
        add(dp[x][s][lim][lead],
            z[s - 1] * dfs(x + 1, s, lim & (i == up), lead & (i == 0)) %
                1000000007);
    }
    if (i == 1) {
      if (!lead) {
        if (!s)
          add(dp[x][s][lim][lead],
              dfs(x + 1, s, lim & (i == up), lead & (i == 0)) % 1000000007);
        else
          add(dp[x][s][lim][lead],
              z[s - 1] * dfs(x + 1, s, lim & (i == up), lead & (i == 0)) %
                  1000000007);
      }
      add(dp[x][s][lim][lead], dfs(x + 1, s + 1, lim & (i == up), 0));
    }
  }
  return dp[x][s][lim][lead];
}
signed main() {
  n = read();
  long long x = n;
  while (x) a[++len] = x & 1, x /= 2;
  reverse(a + 1, a + 1 + len);
  z[0] = 1;
  for (long long i = 1; i <= len; i++)
    z[i] = (z[i - 1] + z[i - 1]) % 1000000007;
  printf("%lld\n", (dfs(1, 0, 1, 1) + 1) % 1000000007);
}
