#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p);
template <class T>
ostream &operator<<(ostream &os, vector<T> &v);
template <class T>
ostream &operator<<(ostream &os, set<T> &v);
inline void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
const long long nmax = 2e5 + 7;
const long long mod = 1e9 + 7;
const long long MAXBIT = 60;
long long n;
long long dp[70][3][3];
long long solve(long long pos, long long mod, long long ok) {
  ;
  if (pos == MAXBIT) return (mod == 0 && ok == 0);
  long long &ret = dp[pos][mod][ok];
  if (ret != -1) return ret;
  long long nthbit = (n >> pos) & 1;
  ret = 0;
  for (long long a = 0; a < 2; a++) {
    for (long long b = 0; b <= a; b++) {
      long long curbit = (a + b + mod) % 2;
      long long nmod = (a + b + mod) / 2;
      long long nok = ok;
      if (curbit < nthbit) nok = 0;
      if (curbit > nthbit) nok = 1;
      ret = (ret + solve(pos + 1, nmod, nok));
      ret = ret % mod;
    }
  }
  return ret;
}
int32_t main() {
  optimizeIO();
  cin >> n;
  memset(dp, -1, sizeof dp);
  long long ans = solve(0, 0, 0);
  ;
  cout << ans << "\n";
  return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "} ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
