#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<int> vec;
int comb[100][100];
int dp[40][40][2];
int calc(int bit, int taken, int flag) {
  if (bit == 31) return 1;
  int &ret = dp[bit][taken][flag];
  if (ret != -1) return ret;
  ret = 0;
  if (!(flag == 0 && vec[bit] == 0))
    ret = calc(bit + 1, taken + 1, flag ? flag : 0);
  for (int cnt = 0; cnt <= taken; cnt++) {
    int on = cnt % 2;
    if (!flag && on > vec[bit]) continue;
    long long theta = comb[taken][cnt];
    theta *= calc(bit + 1, taken, flag ? flag : on < vec[bit]);
    theta %= MOD;
    ret += theta;
    ret %= MOD;
  }
  return ret;
}
int main() {
  int K;
  cin >> K;
  while (K > 0) {
    vec.push_back(K % 2);
    K /= 2;
  }
  while (vec.size() < 31) vec.push_back(0);
  reverse(vec.begin(), vec.end());
  memset(dp, -1, sizeof(dp));
  comb[0][0] = 1;
  for (int j = 1; j <= 50; j++) {
    comb[j][0] = 1;
    for (int i = 1; i <= j; i++)
      comb[j][i] = (comb[j - 1][i] + comb[j - 1][i - 1]) % MOD;
  }
  cout << calc(0, 0, 0) << endl;
}
