#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
int bsr(int x) { return 31 - __builtin_clz(x); }
template <uint MD>
struct ModInt {
  uint v;
  ModInt() : v{0} {}
  ModInt(ll v) : v{normS(v % MD + MD)} {}
  static uint normS(const uint &x) { return (x < MD) ? x : x - MD; };
  static ModInt make(const uint &x) {
    ModInt m;
    m.v = x;
    return m;
  }
  ModInt operator+(const ModInt &r) const { return make(normS(v + r.v)); }
  ModInt operator-(const ModInt &r) const { return make(normS(v + MD - r.v)); }
  ModInt operator*(const ModInt &r) const { return make((ull)v * r.v % MD); }
  ModInt &operator+=(const ModInt &r) { return *this = *this + r; }
  ModInt &operator-=(const ModInt &r) { return *this = *this - r; }
  ModInt &operator*=(const ModInt &r) { return *this = *this * r; }
  static ModInt inv(const ModInt &x) { return pow(ModInt(x), MD - 2); }
};
using Mint = ModInt<TEN(9) + 7>;
map<ll, Mint> dp;
Mint calc(ll N) {
  if (N == 0) return 1;
  if (dp.count(N)) return dp[N];
  Mint ans = 0;
  for (int i = 0; i <= 2; i++) {
    if (N < i) break;
    ans += calc((N - i) / 2);
  }
  return ans;
}
int main() {
  ll n;
  cin >> n;
  cout << calc(n).v << endl;
  return 0;
}
