#include <bits/stdc++.h>
using namespace std;
const double EPS = -1e8;
const double Pi = acos(-1);
bool inline equ(double a, double b) { return fabs(a - b) < EPS; }
const long long MOD = 1000000007ll;
inline long long add(long long a, long long b) { return (a + b) % MOD; }
inline long long mul(long long a, long long b) { return (a * b) % MOD; }
inline long long bit(long long x, long long i) {
  return (x & (1ll << i)) > 0ll;
}
long long n;
long long dp[33][33][2];
bool vis[33][33][2];
long long dfs(int nbt, int cntbs, int fl) {
  if (nbt < 0) return 1ll;
  if (vis[nbt][cntbs][fl]) return dp[nbt][cntbs][fl];
  vis[nbt][cntbs][fl] = 1;
  long long &res = dp[nbt][cntbs][fl];
  if (fl) {
    long long r1 = dfs(nbt - 1, cntbs + 1, 1);
    long long r2 = dfs(nbt - 1, cntbs, 1);
    r2 = mul(r2, (1ll << cntbs));
    res = add(r1, r2);
    return res;
  }
  if (bit(n, nbt)) {
    res = dfs(nbt - 1, cntbs + 1, 0);
    if (cntbs) {
      long long r1 = dfs(nbt - 1, cntbs, 0);
      long long r2 = dfs(nbt - 1, cntbs, 1);
      res = add(res, mul(r1, 1ll << (cntbs - 1)));
      res = add(res, mul(r2, 1ll << (cntbs - 1)));
    } else {
      long long r1 = dfs(nbt - 1, cntbs, 1);
      res = add(res, r1);
    }
  } else {
    long long r1 = dfs(nbt - 1, cntbs, 0);
    if (cntbs)
      res = mul(r1, 1ll << (cntbs - 1));
    else
      res = r1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  cout << dfs(31, 0, 0) << '\n';
}
