#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
long long dp[40][40][2], n, ans;
int lim[45], len;
int calc(int x, int sgn) {
  if (x == 0) return sgn ^ 1;
  return 1 << x >> 1;
}
int main() {
  cin >> n;
  if (n == 0) return puts("1"), 0;
  while (n) {
    lim[++len] = n & 1;
    n >>= 1;
  }
  reverse(lim + 1, lim + len + 1);
  dp[0][0][1] = 1;
  for (int i = 0; i < len; ++i)
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k < 2; ++k) {
        (dp[i + 1][j][k & (lim[i + 1] ^ 1)] +=
         1ll * dp[i][j][k] * calc(j, 0) % p) %= p;
        if ((!k) || lim[i + 1]) {
          (dp[i + 1][j][k] += 1ll * dp[i][j][k] * calc(j, 1) % p) %= p;
          (dp[i + 1][j + 1][k] += dp[i][j][k]) %= p;
        }
      }
  for (int i = 0; i <= len; ++i)
    (ans += (dp[len][i][0] + dp[len][i][1]) % p) %= p;
  printf("%lld\n", ans);
  return 0;
}
