#include <bits/stdc++.h>
using namespace std;
template <class T, class S>
bool chmax(T &a, const S &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class S>
bool chmin(T &a, const S &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long n, long long m) { return (m ? gcd(m, n % m) : n); }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
map<long long, long long> dp;
map<long long, long long> dp2;
long long mod = 1000000007;
long long f(long long n) {
  if (dp[n]) return dp[n];
  if (n == 0) return dp[n] = 1;
  if (n % 2 == 0) return dp[n] = f(n / 2) + f(n / 2 - 1);
  return dp[n] = f(n / 2);
}
long long sum(long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return (3 * sum(n / 2 - 1) + f(n / 2)) % mod;
  else
    return (3 * sum(n / 2) - f(n / 2)) % mod;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  long long n;
  cin >> n;
  cout << sum(n) << '\n';
}
