#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MAXB = 33;
int K;
long long ans;
int bk[MAXB];
int nk[MAXB];
long long find() {
  long long dp[MAXB];
  for (int i = 0; i < MAXB; i++) dp[i] = 0;
  dp[0] = 1;
  for (int i = MAXB - 1; i >= 0; i--) {
    long long ndp[MAXB];
    for (int j = 0; j < MAXB; j++) ndp[j] = 0;
    if (nk[i] == 0) {
      for (int j = 1; j < MAXB; j++) ndp[j] = (dp[j] * (1LL << (j - 1))) % MOD;
      ndp[0] = dp[0];
    } else if (nk[i] == 1) {
      for (int j = 1; j < MAXB; j++) ndp[j] = (dp[j] * (1LL << (j - 1))) % MOD;
      for (int j = MAXB - 1; j >= 0; j--)
        ndp[j + 1] = (ndp[j + 1] + dp[j]) % MOD;
    } else {
      for (int j = 0; j < MAXB; j++) ndp[j] = (dp[j] * (1LL << j)) % MOD;
      for (int j = MAXB - 1; j >= 0; j--)
        ndp[j + 1] = (ndp[j + 1] + dp[j]) % MOD;
    }
    for (int j = 0; j < MAXB; j++) {
      dp[j] = ndp[j];
    }
  }
  long long res = 0;
  for (int i = 0; i < MAXB; i++) res = (res + dp[i]) % MOD;
  return res;
}
long long solve(int x) {
  for (int i = x + 1; i < MAXB; i++) nk[i] = bk[i];
  nk[x] = 0;
  for (int i = x - 1; i >= 0; i--) nk[i] = 2;
  return find();
}
int main() {
  cin >> K;
  int tk = K;
  for (int i = 0; i < MAXB; i++) {
    bk[i] = tk % 2;
    tk /= 2;
  }
  ans = 0;
  for (int i = 0; i < MAXB; i++)
    if (bk[i] == 1) ans = (ans + solve(i)) % MOD;
  for (int i = 0; i < MAXB; i++) nk[i] = bk[i];
  ans = (ans + find()) % MOD;
  cout << ans << "\n";
  return 0;
}
