#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long n;
map<pair<long long, long long>, int> M;
inline void upd(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
inline int dfs(long long x, long long y) {
  if (!y) return 1;
  if (M.count(make_pair(x, y))) return M[make_pair(x, y)];
  int res = dfs(x >> 1, y >> 1);
  upd(res, dfs(x - 1 >> 1, y - 1 >> 1));
  if (y >= 2) upd(res, dfs(x >> 1, y - 2 >> 1));
  return M[make_pair(x, y)] = res;
}
int main() {
  scanf("%lld", &n);
  printf("%lld", M[make_pair(n, n)]);
}
