#include <bits/stdc++.h>
const int mod = 1000000007;
long long pw2[99];
long long f_rlen[99][99];
inline void upda(long long &a, long long b) { a = (a + b) % mod; }
inline void init_f_rlen() {
  pw2[0] = 1;
  for (int i = 1; i <= 91; ++i) pw2[i] = pw2[i - 1] * 2 % mod;
  f_rlen[0][0] = 1;
  for (int rlen = 1; rlen <= 90; ++rlen)
    for (int rlen1 = 0; rlen1 <= rlen; ++rlen1) {
      if (rlen1)
        f_rlen[rlen][rlen1] =
            f_rlen[rlen - 1][rlen1 - 1] * pw2[rlen - rlen1] % mod;
      if (rlen1 < rlen)
        f_rlen[rlen][rlen1] =
            (f_rlen[rlen][rlen1] + f_rlen[rlen - 1][rlen1]) % mod;
    }
}
long long g_pf[44][44];
inline long long calc_prefix(int pf, int rlen) {
  long long ans = 0;
  for (int rlen1 = 0; rlen1 <= rlen; ++rlen1) {
    long long t1ans = 0;
    memset(g_pf, 0, sizeof(g_pf));
    g_pf[0][0] = 1;
    for (int pfmv = 0; (pf >> pfmv); ++pfmv)
      for (int pfmv1 = 0; pfmv1 <= pfmv; ++pfmv1) {
        if ((pf >> pfmv) == 1)
          t1ans = (t1ans + g_pf[pfmv][pfmv1]) % mod;
        else {
          upda(g_pf[pfmv + 1][pfmv1], g_pf[pfmv][pfmv1]);
          if (pf >> pfmv & 1)
            upda(g_pf[pfmv + 1][pfmv1 + 1],
                 g_pf[pfmv][pfmv1] * pw2[pfmv - pfmv1 + rlen - rlen1]);
        }
      }
    ans = (ans + t1ans * pw2[rlen - rlen1] % mod * f_rlen[rlen][rlen1]) % mod;
  }
  return ans;
}
inline long long calc_ans(int n) {
  if (n == 0) return 1;
  long long ans = 1;
  int len0;
  for (len0 = 0; (1 << (len0 + 1)) <= n; ++len0)
    ans = (ans + calc_prefix(1, len0)) % mod;
  int t_pf = 1;
  for (int i = len0 - 1; i >= 0; --i) {
    int a = n >> i & 1;
    if (!a)
      t_pf <<= 1;
    else {
      ans = (ans + calc_prefix(t_pf << 1, i)) % mod;
      t_pf = t_pf << 1 | 1;
    }
  }
  ans = (ans + calc_prefix(n, 0)) % mod;
  return ans;
}
int main() {
  init_f_rlen();
  int k;
  scanf("%d", &k);
  printf("%I64d\n", calc_ans(k));
  return 0;
}
