#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
const int MAX_N = 100000;
pair<long long, long long> a(long long n) {
  if (n == 1) return {1, 0};
  if (n == 2) return {2, 1};
  if (n % 2 == 1) {
    long long k = n / 2;
    auto [a1, a0] = a(k);
    return {2 * a1 + a0, a1 + 2 * a0};
  }
  return {a(n + 1).second, a(n - 1).first};
}
map<long long, map<long long, long long>> memo;
long long f(long long S, long long X) {
  if (memo[S].find(X) != memo[S].end()) {
    return memo[S][X];
  }
  long long ret = 0;
  if (S - 2 >= 0) ret += f((S - 2) / 2, X / 2);
  if (S - 1 >= 0 && X - 1 >= 0) ret += f((S - 1) / 2, (X - 1) / 2);
  ret += f(S / 2, X / 2);
  return memo[S][X] = ret % p;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(std::numeric_limits<float>::max_digits10);
  long long n;
  cin >> n;
  memo[0][0] = 1;
  memo[1][0] = 1;
  memo[0][1] = 1;
  memo[1][1] = 2;
  cout << f(n, n) << endl;
  return 0;
}
