#include <bits/stdc++.h>
int mod = 1e9 + 7;
using namespace std;
map<int, int> q;
int solve(int n) {
  if (q[n]) {
    return q[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() {
  int n;
  scanf("%lld", &n);
  printf("%d\n", solve(n));
}
