#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
map<long long, long long> q;
long long a[100];
long long solve(long long n) {
  if (n == 0) {
    return q[n] = 1;
  }
  if (n == 1) {
    return q[n] = 2;
  }
  if (n % 2 == 0) {
    return q[n] = (2 * solve(n / 2 - 1) + solve(n / 2)) % mod;
  }
  if (n % 2) {
    return q[n] = (solve(n / 2 - 1) + 2 * solve(n / 2)) % mod;
  }
}
int main() {
  long long n;
  scanf("%lld", &n);
  solve(n);
  printf("%lld\n", q[n]);
  return 0;
}
