#include <bits/stdc++.h>
const int mod = 1e9 + 7;
int k, len;
int lim[35];
long long dp[35][35][2], ans;
signed main() {
  scanf("%d", &k);
  if (k == 0) return !printf("1\n");
  while (k) {
    lim[++len] = k & 1;
    k >>= 1;
  }
  std::reverse(lim + 1, lim + len + 1);
  dp[0][0][1] = 1;
  for (int register i = 0; i < len; ++i) {
    for (int register j = 0; j <= i; ++j)
      for (int register k = 0; k < 2; ++k) {
        dp[i + 1][j][k & (lim[i + 1] ^ 1)] += dp[i][j][k] << (j ? j - 1 : 0);
        if (!k || lim[i + 1]) {
          if (j) dp[i + 1][j][k] += dp[i][j][k] << j >> 1;
          dp[i + 1][j + 1][k] += dp[i][j][k];
        }
      }
    for (int register j = 0; j <= i + 1; ++j)
      for (int register k = 0; k < 2; ++k) dp[i + 1][j][k] %= mod;
  }
  for (int register i = 0; i <= len; ++i) ans += dp[len][i][0] + dp[len][i][1];
  printf("%lld", ans % mod);
  return 0;
}
