#include <bits/stdc++.h>
const int N = 50;
int A[N], f[N][N][2];
long long pw[N];
int DFS(int bit, int cnt, bool lim) {
  if (~f[bit][cnt][lim]) return f[bit][cnt][lim];
  if (!bit) return 1;
  long long res = 0;
  if (!lim)
    res = DFS(bit - 1, cnt + 1, 0) + pw[cnt] * DFS(bit - 1, cnt, 0);
  else
    res = (cnt ? pw[cnt - 1] : 1ll) * DFS(bit - 1, cnt, !A[bit]) +
          (A[bit] ? DFS(bit - 1, cnt + 1, 1) +
                        (cnt ? pw[cnt - 1] : 0ll) * DFS(bit - 1, cnt, 1)
                  : 0);
  res %= 1000000007;
  return f[bit][cnt][lim] = res;
}
int main() {
  int K, bit = 0;
  scanf("%d", &K);
  while (K) A[++bit] = K & 1, K >>= 1;
  pw[0] = 1;
  for (int i = 1; i <= bit; ++i) pw[i] = pw[i - 1] << 1;
  memset(f, 0xff, sizeof f);
  printf("%d\n", DFS(bit, 0, 1));
  return 0;
}
