#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long ch = getchar(), f = 1, ans = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    ans = (((ans << 2) + ans) << 1) + (ch ^ '0');
  return f ? ans : -ans;
}
const int maxn = 35;
const int mod = 1e9 + 7;
long long f[maxn][maxn][2];
int k;
long long dp(int i, int cnt, int limit) {
  if (i < 0) return 1;
  long long &ans = f[i][cnt][limit];
  if (~ans) return ans;
  ans = 0;
  int d = (k >> i) & 1;
  if (!limit || d == 1) ans = (ans + dp(i - 1, cnt + 1, limit) % mod);
  if (!cnt) {
    ans = (ans + dp(i - 1, cnt, limit && (d == 0)) % mod);
  } else {
    if (!limit || d == 1)
      ans = (ans + (dp(i - 1, cnt, limit) << (cnt - 1)) % mod);
    ans = (ans + (dp(i - 1, cnt, limit && (d == 0)) << (cnt - 1)) % mod);
  }
  return ans;
}
inline int calc() {
  memset(f, -1, sizeof f);
  return dp(31, 0, 1);
}
int main() {
  k = read();
  cout << calc() << endl;
  return 0;
}
