#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 and y == 0LL) return 1LL;
  if (M[pair<long long, long long>(x, y)] != 0LL)
    return M[pair<long long, long long>(x, y)];
  else {
    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 >= 2LL 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;
  cout << rec((long long)n, (long long)n) << endl;
};
