#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long pow_mod(long long x, long long n) {
  long long ret = 1LL;
  while (n > 0) {
    if (n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
long long N;
long long rec(long long digit, int happen, bool limit) {
  if (digit == -1) {
    if (happen == 0) return (0);
    return (pow_mod(2, happen));
  }
  if (!limit && happen > 0) {
    return (pow_mod(2, happen - 1) * pow_mod(3, digit + 1) % mod);
  }
  long long end = 1;
  if (limit && !((N >> digit) & 1)) end--;
  long long ret = 0;
  for (long long i = end; i >= 0; i--) {
    (ret += rec(digit - 1, happen + i, limit & (i == end))) %= mod;
  }
  return (ret);
}
int main() {
  cin >> N;
  ++N;
  cout << rec(60, 0, true) << endl;
}
