#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, K = 30;
inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(int a, int b) { return a >= b ? a - b : a - b + mod; }
inline int mul(int a, int b) { return 1ll * a * b % mod; }
inline int power(int a, int b) {
  int res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
  }
  return res;
}
int f[K + 5][K + 5][2], val[K + 5], n, res;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  val[0] = 1;
  for (int i = 1; i <= K; i++) val[i] = mul(2, val[i - 1]);
  f[K][0][1] = 1;
  for (int i = K; i >= 1; i--)
    for (int j = 0; j <= K; j++) {
      f[i - 1][j + 1][0] = add(f[i - 1][j + 1][0], f[i][j][0]);
      f[i - 1][j][0] = add(f[i - 1][j][0], mul(val[j], f[i][j][0]));
      int even = j ? val[j - 1] : 1, odd = j ? val[j - 1] : 0;
      if (!(n >> (i - 1) & 1)) {
        f[i - 1][j][1] = add(f[i - 1][j][1], mul(even, f[i][j][1]));
      } else {
        f[i - 1][j + 1][1] = add(f[i - 1][j + 1][1], f[i][j][1]);
        f[i - 1][j][0] = add(f[i - 1][j][0], mul(even, f[i][j][1]));
        f[i - 1][j][1] = add(f[i - 1][j][1], mul(odd, f[i][j][1]));
      }
    }
  for (int i = 0; i <= K; i++)
    res = add(res, f[0][i][0]), res = add(res, f[0][i][1]);
  cout << res << endl;
  return 0;
}
