#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
inline bool read(int& val) { return scanf("%d", &val) != -1; }
inline bool read(long long& val) { return scanf("%I64d", &val) != -1; }
inline bool read(double& val) { return scanf("%lf", &val) != -1; }
inline bool read(char* val) { return scanf("%s", val) != -1; }
template <class T1, class T2>
inline bool read(T1& a, T2& b) {
  return read(a) && read(b);
}
template <class T1, class T2, class T3>
inline bool read(T1& a, T2& b, T3& c) {
  return read(a) && read(b) && read(c);
}
template <class T1, class T2, class T3, class T4>
inline bool read(T1& a, T2& b, T3& c, T4& d) {
  return read(a) && read(b) && read(c) && read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) {
  return read(a) && read(b) && read(c) && read(d) && read(e);
}
const int N = 64;
const long long mod = 1000000007;
int val[N];
long long dp[N][2][2][2];
void add(long long& a, long long b, long long mod) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
long long dfs(int p, int up, bool xorlimit, bool sumlimit) {
  long long& ret = dp[p][up][xorlimit][sumlimit];
  if (p == -1) return up == 0;
  if (ret == -1) {
    ret = 0;
    int maxu = xorlimit ? val[p] : 2;
    int maxv = sumlimit ? val[p] : 2;
    if (maxu >= 0) {
      if (maxv >= 0) add(ret, dfs(p - 1, 0, maxu == 0, maxv == 0), mod);
      if (maxv >= 1) add(ret, dfs(p - 1, 1, maxu == 0, maxv == 1), mod);
    }
    if (maxu >= 1) {
      if (up == 1 && maxv >= 0)
        add(ret, dfs(p - 1, 1, maxu == 1, maxv == 0), mod);
      if (up == 0 && maxv >= 1)
        add(ret, dfs(p - 1, 0, maxu == 1, maxv == 1), mod);
    }
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  for (int i = 0, _ = (N); i < _; ++i) val[i] = (n & (1 << i)) >> i;
  memset(&dp, -1, sizeof(dp));
  cout << dfs(63, 0, 1, 1);
  return 0;
}
