#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 35;
long long DP[maxn][maxn][2];
int a[maxn];
int N = 0;
long long K;
int main() {
  cin >> K;
  if (!K) a[++N] = 0;
  while (K) {
    a[++N] = K % 2;
    K /= 2;
  }
  reverse(a + 1, a + N + 1);
  DP[0][0][1] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= i; ++j) {
      DP[i][j][0] = (DP[i][j][0] + (1ll << j) * DP[i - 1][j][0] % mod) % mod;
      if (j) DP[i][j][0] = (DP[i][j][0] + DP[i - 1][j - 1][0]) % mod;
      long long odd = (j > 0) ? (1ll << (j - 1)) % mod : 0;
      long long even = (j > 0) ? (1ll << (j - 1)) % mod : 1;
      if (a[i] == 0) {
        DP[i][j][1] = (DP[i][j][1] + even * DP[i - 1][j][1] % mod) % mod;
      } else {
        if (j) DP[i][j][1] = (DP[i][j][1] + DP[i - 1][j - 1][1]) % mod;
        DP[i][j][1] = (DP[i][j][1] + odd * DP[i - 1][j][1] % mod) % mod;
        DP[i][j][0] = (DP[i][j][0] + even * DP[i - 1][j][1] % mod) % mod;
      }
    }
  }
  long long ret = 0;
  for (int i = 0; i <= N; ++i) {
    ret = (ret + (DP[N][i][0] + DP[N][i][1]) % mod) % mod;
  }
  cout << ret << endl;
}
