#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int x, n;
long long dp[33][33][2];
long long f(int d, int k = 0, bool fg = false) {
  if (d < 0) return 1;
  long long &ret = dp[d][k][fg];
  if (ret >= 0) return ret;
  ret = 0;
  long long mul = k ? (1 << (k - 1)) : 0;
  if (fg) {
    if (d < 0) return 1;
    ret = f(d - 1, k + 1, true);
    if (mul == 0)
      ret += f(d - 1, k, true);
    else
      ret += mul * f(d - 1, k, true) % mod + mul * f(d - 1, k, true) % mod;
    return ret = ret % mod;
  }
  int b = x & (1 << d);
  if (b) {
    ret = f(d - 1, k + 1);
    if (mul == 0)
      ret += f(d - 1, k, true);
    else
      ret += mul * f(d - 1, k) % mod + mul * f(d - 1, k, true) % mod;
  } else {
    if (mul == 0)
      ret = f(d - 1, k);
    else
      ret = mul * f(d - 1, k);
  }
  return ret = ret % mod;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &x);
  for (n = 0; (1 << (n)) <= x; ++n)
    ;
  int ans = f(n - 1);
  printf("%d\n", ans);
  return 0;
}
