#include <bits/stdc++.h>
long long MOD = 1000000007;
long long dp[40][40], a[40], tmp[40][40];
std::vector<long long> bit;
long long power(long long x) {
  long long g = 1;
  for (long long k = 1; k <= x; k++) {
    g *= 2;
    g %= MOD;
  }
  return g;
}
void ini() {
  int k, i;
  a[0] = 1;
  dp[0][1] = 1;
  for (k = 1; k <= 35; k++) {
    for (i = k + 1; i >= 1; i--) {
      dp[k][i] = dp[k - 1][i] + power(k - i + 1) * dp[k - 1][i - 1];
      dp[k][i] %= MOD;
      a[k] += dp[k][i];
      a[k] %= MOD;
    }
  }
}
int main() {
  ini();
  long long n, t = 0, ans = 0, p, k, i, c, j, q;
  int s;
  scanf("%I64d", &n);
  n++;
  while (n) {
    t++;
    if (n % 2) bit.push_back(t);
    n /= 2;
  }
  ans += a[t - 1];
  s = bit.size();
  for (k = s - 2; k >= 0; k--) {
    p = bit[k];
    memset(tmp, 0, sizeof(tmp));
    for (i = 1; i <= p + 1; i++) {
      tmp[0][i] = dp[p][i] - dp[p - 1][i];
      tmp[0][i] %= MOD;
      if (tmp[0][i] < 0) tmp[0][i] += MOD;
    }
    for (i = k + 1; i < s - 1; i++) {
      c = i - k;
      for (j = p + 1 + c; j >= 1; j--) {
        tmp[c][j] = tmp[c - 1][j] + power(bit[i] - j + 2) * tmp[c - 1][j - 1];
        tmp[c][j] %= MOD;
      }
    }
    q = 0;
    for (i = 1; i <= 36; i++) {
      q += tmp[s - k - 2][i];
      q %= MOD;
    }
    ans += q;
    ans %= MOD;
  }
  printf("%I64d", ans);
}
