#include <bits/stdc++.h>
using namespace std;
const int INF = 999999999;
const int N = 351000;
const int M = 1000010;
const int mod = 1000000007;
int a[100], f[50][50], g[50][50];
long long po[50];
void work() {
  int i, j, k, t, n;
  long long ans = 0;
  for (po[0] = i = 1; i <= 40; ++i) po[i] = po[i - 1] << 1, po[i] %= mod;
  scanf("%d", &k);
  for (i = 1, t = k; t; t >>= 1, ++i) a[i] = t & 1;
  n = i - 1;
  g[n + 1][0] = 1;
  for (i = n; i >= 1; --i) {
    f[i][0] = 1;
    for (j = 1; j <= (n - i + 1); ++j) {
      f[i][j] = (f[i + 1][j] * po[j] + f[i + 1][j - 1]) % mod;
      if (a[i] == 0) {
        g[i][j] = g[i + 1][j] * po[j - 1] % mod;
      } else if (a[i] == 1) {
        f[i][j] = (f[i][j] + g[i + 1][j] * po[j - 1]) % mod;
        g[i][j] = (g[i + 1][j] * po[j - 1] + g[i + 1][j - 1]) % mod;
      }
    }
  }
  for (i = 0; i <= n; ++i) ans += f[1][i] + g[1][i];
  ans %= mod;
  printf("%I64d\n", ans);
}
int main() {
  work();
  return 0;
}
