#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 nil = -1;
const int N = 100;
const long long mod = 1000000007;
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 dp[N][4];
long long cnt[N];
int val[N];
int main() {
  long long n;
  cin >> n;
  n++;
  for (int i = 0, _ = (64); i < _; ++i) {
    if (n & (1ll << i))
      val[i] = 1;
    else
      val[i] = 0;
  }
  dp[0][0] = 1;
  dp[0][3] = 1;
  for (int i = 0, _ = (64); i < _; ++i) {
    add(dp[i + 1][0], dp[i][0], mod);
    add(dp[i + 1][0], dp[i][1], mod);
    add(dp[i + 1][0], dp[i][3], mod);
    add(dp[i + 1][1], dp[i][0], mod);
    add(dp[i + 1][1], dp[i][1], mod);
    add(dp[i + 1][1], dp[i][2], mod);
    add(dp[i + 1][2], dp[i][0], mod);
    add(dp[i + 1][2], dp[i][1], mod);
    add(dp[i + 1][2], dp[i][2], mod);
    add(dp[i + 1][3], dp[i][0], mod);
    add(dp[i + 1][3], dp[i][1], mod);
    add(dp[i + 1][3], dp[i][3], mod);
  }
  cnt[0] = 0;
  for (int i = 0, _ = (64); i < _; ++i)
    cnt[i + 1] = dp[i][0] + dp[i][1] + dp[i][3];
  long long ans = 0;
  long long mul = 0;
  for (int i = 0, _ = (64); i < _; ++i) {
    if (val[i] == 1) {
      ans = (cnt[i] + mul * ans) % mod;
      mul = 1;
    } else
      mul++;
  }
  cout << ans << endl;
  return 0;
}
