#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
const lint MOD = 1e9 + 7;

map<lint, lint> memo;
lint rec(lint n) {
  if (memo.count(n)) return memo[n];
  lint res = 0;
  if (n % 2) {
    res = 2 * rec(n / 2) + rec(n / 2 - 1);
  } else {
    res = rec(n / 2) + 2 * rec(n / 2 - 1);
  }
  return memo[n] = res % MOD;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  lint n; cin >> n;
  memo[-1] = 0;
  memo[0] = 1;
  cout << rec(n) << '\n';
  return 0;
}