#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool maxup(T& a, T&& b) {
  if (a < b) {
    a = b;
    return true;
  };
}
template <typename T>
bool maxup(T& a, T& b) {
  if (a < b) {
    a = b;
    return true;
  };
}
template <typename T>
bool minup(T& a, T&& b) {
  if (a > b) {
    a = b;
    return true;
  };
}
template <typename T>
bool minup(T& a, T& b) {
  if (a > b) {
    a = b;
    return true;
  };
}
using VV = vector<vector<long long>>;
using V = vector<long long>;
using P = pair<long long, long long>;
using IP = pair<long long, P>;
template <typename T>
inline void input(vector<T>& v) {
  for (auto& x : v) cin >> x;
}
long long Cb[65][65];
signed main() {
  const long long mod = 1e9 + 7;
  Cb[0][0] = 1;
  for (signed i = signed(0); i < signed(64); i++)
    for (signed j = signed(0); j < signed(64); j++) {
      (Cb[i + 1][j] += Cb[i][j]) %= mod;
      (Cb[i + 1][j + 1] += Cb[i][j]) %= mod;
    }
  long long N;
  cin >> N;
  long long sum = ((N % 2 + 1 + N + 1) / 2) % mod * (N / 2 + 1) % mod;
  long long bs = 0;
  long long ovs = 0;
  for (long long i = 63; i >= 0; i--)
    if ((N >> i) & 1) {
      (ovs += (1 << max(bs - 1, 0ll))) %= mod;
      for (signed j = signed(1); j < signed(i + 1); j++) {
        (ovs += (Cb[i][j] * ((1 << (bs + j - 1)) % mod)) % mod) %= mod;
      }
      bs++;
    }
  (ovs += (1 << max(bs - 1, 0ll))) %= mod;
  cout << (sum - ovs + N + 1) % mod << endl;
  system("pause");
}
