#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int logn = 31;
void upd(long long& a, const long long& b) {
  a += b;
  if (a >= mod) a -= mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<long long> pwr(logn + 1, 1);
  for (int i = 1; i < logn; i++) pwr[i] = (pwr[i - 1] << 1ll) % mod;
  long long k;
  cin >> k;
  vector<vector<vector<long long> > > dp(
      logn, vector<vector<long long> >(logn, vector<long long>(2, 0)));
  dp[logn - 1][0][1] = 1;
  for (long long last = logn - 1; last > 0; last--) {
    for (long long basis = 0; basis < logn; basis++) {
      for (long long match = 0; match < 2; match++) {
        if (dp[last][basis][match] == 0) continue;
        if (!match || (k & (1ll << (last - 1))))
          upd(dp[last - 1][basis + 1][match], dp[last][basis][match]);
        upd(dp[last - 1][basis][match && ((k & (1ll << (last - 1))) == 0)],
            (dp[last][basis][match] * (basis == 0 ? 1ll : pwr[basis - 1])) %
                mod);
        if (basis && (!match || (k & (1ll << (last - 1)))))
          upd(dp[last - 1][basis][match],
              (dp[last][basis][match] * pwr[basis - 1]) % mod);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < logn; i++)
    ans = (ans + dp[0][i][0] + dp[0][i][1]) % mod;
  cout << ans << "\n";
  return 0;
}
