#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int K = 30;
int n, f[K + 10][K + 10][2], fac[K + 20];
int Sum(int x, int y) {
  x += y;
  return (x >= mo) ? x - mo : x;
}
int Mul(int x, int y) { return (long long)x * y % mo; }
void work() {
  fac[0] = 1;
  for (int i = 1; i <= K + 10; i++) fac[i] = Mul(fac[i - 1], 2);
  f[K + 1][0][0] = 1;
  for (int i = K; i >= 0; i--) {
    for (int j = 0; j <= K - i; j++) {
      if (f[i + 1][j][1]) {
        f[i][j + 1][1] = Sum(f[i][j + 1][1], f[i + 1][j][1]);
        f[i][j][1] = Sum(f[i][j][1], Mul(f[i + 1][j][1], fac[j]));
      }
      if (f[i + 1][j][0]) {
        if (n & (1 << i)) {
          f[i][j + 1][0] = Sum(f[i][j + 1][0], f[i + 1][j][0]);
          if (j)
            f[i][j][1] = Sum(f[i][j][1], Mul(f[i + 1][j][0], fac[j - 1]));
          else
            f[i][j][1] = Sum(f[i][j][1], f[i + 1][j][0]);
          if (j) f[i][j][0] = Sum(f[i][j][0], Mul(f[i + 1][j][0], fac[j - 1]));
        } else {
          if (j)
            f[i][j][0] = Sum(f[i][j][0], Mul(f[i + 1][j][0], fac[j - 1]));
          else
            f[i][j][0] = Sum(f[i][j][0], f[i + 1][j][0]);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= K + 1; i++) ans = Sum(ans, Sum(f[0][i][0], f[0][i][1]));
  printf("%d\n", ans);
}
int main() {
  scanf("%d", &n);
  work();
  return 0;
}
