#include <bits/stdc++.h>
using namespace std;
long long n, M = 1e9 + 7;
map<long long, long long> d;
long long f(long long p) {
  if (p == 0) return 1;
  if (p == 1) return 2;
  if (p == 2) return 4;
  if (d[p]) return d[p];
  if (p & 1)
    return d[p] = (2 * f(n / 2) + f(n / 2 - 1)) % M;
  else
    return d[p] = (f(n / 2) + 2 * f(n / 2 - 1)) % M;
}
int main() {
  cin >> n;
  cout << f(n);
  return 0;
}
