#include <bits/stdc++.h>
using namespace std;
map<int, int> num;
const int N = 1e6 + 10;
const int Mod = 1e9 + 7;
long long cal(long long x) {
  if (num[x] != 0) return num[x];
  return num[x] = (cal(x / 2) + cal((x - 1) / 2) + cal((x - 2) / 2)) % Mod;
}
int main() {
  num[0] = 1;
  num[1] = 2;
  long long n;
  scanf("%lld", &n);
  printf("%lld\n", cal(n));
  return 0;
}
