#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
long long f[50][50], g[50][50];
int main() {
  int i, j, t, N;
  long long ans, v;
  scanf("%d", &N);
  f[32][0] = 1;
  for (i = 31; i >= 0; i--) {
    t = (N >> i) & 1;
    for (j = 0; j < 32; j++) {
      if (j == 0)
        v = 1;
      else
        v = (1 << (j - 1));
      g[i][j] += (1LL << j) * g[i + 1][j] % 1000000007;
      if (g[i][j] >= 1000000007) g[i][j] -= 1000000007;
      g[i][j + 1] += g[i + 1][j];
      if (g[i][j + 1] >= 1000000007) g[i][j + 1] -= 1000000007;
      if (t == 0) {
        f[i][j] += v * f[i + 1][j] % 1000000007;
        if (f[i][j] >= 1000000007) f[i][j] -= 1000000007;
      } else {
        f[i][j] += ((1LL << j) - v) * f[i + 1][j] % 1000000007;
        ;
        if (f[i][j] >= 1000000007) f[i][j] -= 1000000007;
        f[i][j + 1] += f[i + 1][j] % 1000000007;
        if (f[i][j + 1] >= 1000000007) f[i][j + 1] %= 1000000007;
        g[i][j] += v * f[i + 1][j] % 1000000007;
        if (g[i][j] >= 1000000007) g[i][j] -= 1000000007;
      }
    }
  }
  for (i = ans = 0; i <= 32; i++) ans += f[0][i] + g[0][i];
  printf("%I64d\n", ans % 1000000007);
  return 0;
}
