#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
int f[31][31][2], c[31], bin[31];
int Dfs(int x, int y, bool flag) {
  if (!x) return 1;
  if (~f[x][y][flag]) return f[x][y][flag];
  int ans = 0, lim = flag ? c[x] : 1;
  if (!flag) {
    (ans += (long long)bin[y] * Dfs(x - 1, y, 0) % md) %= md;
    (ans += Dfs(x - 1, y + 1, 0)) %= md;
  } else {
    (ans += (long long)(!y ? 1 : bin[y - 1]) * Dfs(x - 1, y, lim == 0) % md) %=
        md;
    if (c[x] == 1) {
      (ans += Dfs(x - 1, y + 1, lim == 1)) %= md;
      (ans +=
       (long long)(!y ? 0 : bin[y - 1]) * Dfs(x - 1, y, lim == 1) % md) %= md;
    }
  }
  return f[x][y][flag] = ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int K;
  cin >> K;
  int len = 0;
  for (; K; K >>= 1) c[++len] = K & 1;
  memset(f, -1, sizeof f);
  bin[0] = 1;
  for (int i = (1); i <= (30); ++i) bin[i] = bin[i - 1] << 1;
  cout << Dfs(len, 0, 1) << '\n';
  return 0;
}
