#include <bits/stdc++.h>
using namespace std;
long long R = 1000000000 + 7;
map<pair<long long, long long>, long long> M;
long long rec(long long x, long long y) {
  if (x == 0LL or y == 0LL) return 1LL;
  for (auto it = M.find(pair<long long, long long>(x, y)); it != M.end();)
    return it->second;
  if (M[pair<long long, long long>(x, y)] > 0LL)
    return M[pair<long long, long long>(x, y)];
  long long ans = 0LL;
  if (x >= 0LL and y >= 0LL) ans += rec(x / 2, y / 2) % R;
  if (x > 0LL and y > 0LL) ans += rec((x - 1) / 2, (y - 1) / 2) % R;
  if (x > 1LL and y >= 0) ans += rec((x - 2) / 2, (y) / 2) % R;
  return M[pair<long long, long long>(x, y)] = ans;
}
int main() {
  long long n;
  cin >> n;
  rec((long long)n, (long long)n);
  cout << M[pair<long long, long long>((long long)n, (long long)n)] << endl;
};
