#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30;
const long long MOD = 1000000007;
void trans0(long long a[MAXN + 1]) {
  for (int i = 0; i < MAXN; i++) a[i + 1] = (a[i + 1] * (1LL << i)) % MOD;
}
void trans1(long long a[MAXN + 1]) {
  for (int i = MAXN - 1; i >= 0; i--)
    a[i + 1] = (a[i + 1] * (1LL << i) + a[i]) % MOD;
  a[0] = 0;
}
void trans01(long long a[MAXN + 1]) {
  for (int i = MAXN - 1; i >= 0; i--)
    a[i + 1] = (2 * a[i + 1] * (1LL << i) + a[i]) % MOD;
}
long long calc(int k) {
  k++;
  long long sum = 0;
  for (int i = 0; i < MAXN; i++) {
    if (((1 << i) & k) == 0) continue;
    long long arr[MAXN + 1];
    for (int j = 1; j <= MAXN; j++) arr[j] = 0;
    arr[0] = 1;
    for (int j = MAXN - 1; j >= i; j--) {
      int zbit = (k & (1 << j));
      if (j == i) zbit = 0;
      if (zbit)
        trans1(arr);
      else
        trans0(arr);
    }
    for (int j = i - 1; j >= 0; j--) trans01(arr);
    for (int j = 0; j <= MAXN; j++) sum += arr[j];
  }
  sum %= MOD;
  if (sum < 0) sum += MOD;
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int K;
  cin >> K;
  long long ans = calc(K);
  cout << ans << endl;
  return 0;
}
