#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long f(long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return f(n / 2) + f(n / 2 - 1);
  else
    return 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;
}
int main() {
  long long n;
  cin >> n;
  cout << sum(n) << endl;
}
