#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void add(int &a, int b) {
  a = a + b;
  if (a >= mod) a -= mod;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
int d[33], c[33][33];
int f[33][33][2];
int main() {
  for (int i = 0; i < 33; ++i) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
      if (c[i][j] >= mod) c[i][j] -= mod;
    }
  }
  int k;
  cin >> k;
  for (int i = 0; i < 30; ++i) {
    if ((1 << i) & k) d[i] = 1;
  }
  f[30][0][1] = 1;
  for (int i = 30; i > 0; --i)
    for (int open = 0; open <= 30 - i; ++open)
      for (int eq = 0; eq <= 1; ++eq) {
        int ft = f[i][open][eq];
        if (ft == 0) continue;
        if (d[i - 1] == 1 || eq == 0) add(f[i - 1][open + 1][eq], ft);
        for (int u = 0; u <= open; ++u) {
          if (u & 1) {
            if (d[i - 1] == 1 || eq == 0)
              add(f[i - 1][open][eq], mul(ft, c[open][u]));
          } else {
            int neq = eq;
            if (d[i - 1] == 1) neq = 0;
            add(f[i - 1][open][neq], mul(ft, c[open][u]));
          }
        }
      }
  int ans = 0;
  for (int open = 0; open <= 30; ++open)
    for (int eq = 0; eq <= 1; ++eq) add(ans, f[0][open][eq]);
  cout << ans << endl;
  return 0;
}
