#include <bits/stdc++.h>
using namespace std;
long long f[40][40][2];
int k;
const int MOD = 7 + (int)1e9;
long long dfs(int i, int n, bool e) {
  if (i < 0) return 1;
  long long& res = f[i][n][e];
  if (res >= 0) return res;
  res = 0;
  int limit = ((k >> i) & 1);
  if (e || limit) (res += dfs(i - 1, n + 1, e)) %= MOD;
  if (n == 0)
    (res += dfs(i - 1, n, e | limit)) %= MOD;
  else {
    if (limit || e) (res += dfs(i - 1, n, e) * (1 << (n - 1))) %= MOD;
    (res += dfs(i - 1, n, e | limit) * (1 << (n - 1))) %= MOD;
  }
  return res;
}
int main() {
  cin >> k;
  memset(f, -1, sizeof f);
  cout << dfs(31, 0, 0) << endl;
}
