#include <bits/stdc++.h>
using namespace std;
inline void ad(int& x, long long y) { x = (x + y) % 1000000007; }
int n, f[40][40][2], t[40], c;
int main() {
  scanf("%d", &n);
  f[30][0][1] = 1;
  for (int i = 30; i; --i)
    for (int j = 0; j <= 30; ++j) {
      ad(f[i - 1][j][0], f[i][j][0] * (1ll << j) % 1000000007);
      ad(f[i - 1][j + 1][0], f[i][j][0]);
      int x = j ? (1 << j - 1) : 1, y = j ? (1 << j - 1) : 0;
      if ((n >> i - 1) & 1) {
        ad(f[i - 1][j][0], (long long)x * f[i][j][1] % 1000000007);
        ad(f[i - 1][j][1], (long long)y * f[i][j][1] % 1000000007);
        ad(f[i - 1][j + 1][1], f[i][j][1]);
      } else
        ad(f[i - 1][j][1], (long long)x * f[i][j][1]);
    }
  int A = 0;
  for (int i = 30; ~i; --i) ad(A, f[0][i][0] + f[0][i][1]);
  printf("%d\n", A);
}
