#include <bits/stdc++.h>
template <typename _Tp>
inline void red(_Tp &x) {
  x = 0;
  bool fg = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fg ^= 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (_Tp)(ch ^ 48), ch = getchar();
  if (fg) x = -x;
}
using namespace std;
const int mod = 1e9 + 7;
const int N = 64;
long long dp[N][N][2], pw[N] = {1};
int n, lg;
long long PW(int x) { return x < 0 ? 1 : pw[x]; }
long long DP(int i, int j, bool fg) {
  if (i == -1) return 1;
  if (dp[i][j][fg] != -1) return dp[i][j][fg];
  long long ret = 0;
  int mx = fg ? ((n >> i) & 1) : (1);
  ret = (ret + DP(i - 1, j, mx == 0) * PW(j - 1)) % mod;
  if (mx == 1) {
    ret = (ret + DP(i - 1, j + 1, fg)) % mod;
    if (j > 0) ret = (ret + DP(i - 1, j, fg) * PW(j - 1)) % mod;
  }
  return dp[i][j][fg] = ret;
}
int main() {
  for (int i = 1; i < N; ++i) pw[i] = (pw[i - 1] * 2ll) % mod;
  red(n);
  if (n == 0) {
    printf("1\n");
    return 0;
  }
  lg = log2(n);
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", DP(lg + 1, 0, 1));
  return 0;
}
