#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "{";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "}";
}
int main() {
  const int MOD = 1e9 + 7;
  long long n;
  cin >> n;
  map<long long, long long> store;
  function<long long(int)> eval = [&](long long x) -> long long {
    if (store.find(x) != store.end()) return store[x];
    long long ret;
    if (x == 1) {
      ret = 2;
    } else if (x == 2) {
      ret = 4;
    } else if (x == 3) {
      ret = 5;
    } else {
      if (x % 2 == 0) {
        ret = (2 * eval(x / 2 - 1) + eval(x / 2)) % MOD;
      } else {
        ret = (eval(x / 2 - 1) + 2 * eval(x / 2)) % MOD;
      }
    }
    store[x] = ret;
    return ret;
  };
  cout << eval(n) << '\n';
  return 0;
}
