#include <bits/stdc++.h>
using namespace std;
int F[32][32], G[32][32];
const int MOD = 1000000007;
int main() {
  int K, ans = 0;
  scanf("%d", &K);
  F[30][0] = 1;
  for (int b = 29; b >= 0; --b) {
    F[b][0] = K & (1 << b) ? 0 : F[b + 1][0];
    G[b][0] = G[b + 1][0] + (K & (1 << b) ? F[b + 1][0] : 0);
    for (int n = 1; n <= 30; ++n) {
      long long mult = 1 << (n - 1);
      if (K & (1 << b)) {
        F[b][n] = (F[b + 1][n - 1] + mult * F[b + 1][n]) % MOD;
        G[b][n] =
            (G[b + 1][n - 1] + mult * F[b + 1][n] + mult * 2 * G[b + 1][n]) %
            MOD;
      } else {
        F[b][n] = (mult * F[b + 1][n]) % MOD;
        G[b][n] = (mult * 2 * G[b + 1][n] + G[b + 1][n - 1]) % MOD;
      }
    }
  }
  for (int n = 0; n <= 30; ++n)
    ans = ((long long)ans + F[0][n] + G[0][n]) % MOD;
  printf("%d\n", ans % MOD);
}
