#include <bits/stdc++.h>
long long n;
long long MODULO = (long long)(1e9 + 7);
std::map<long long, std::map<long long, long long>> map;
long long f(long long x, long long y) {
  if (x == 0 && y == 0) return 1;
  if (x < 0 || y < 0) return 0;
  long long& ret = map[x][y];
  if (ret != 0) return ret;
  ret += f(x >> 1, y >> 1);
  ret += f((x - 1) >> 1, (y - 1) >> 1);
  ret += f((x - 2) >> 1, y >> 1);
  return ret % MODULO;
}
int main() {
  std::cin >> n;
  std::cout << f(n, n);
  return 0;
}
