#include <bits/stdc++.h>
using namespace std;
map<long long, map<long long, long> > memo;
long rec(long long S, long long X) {
  if ((!(memo.find(S) == memo.end())) && (!(memo[S].find(X) == memo[S].end())))
    return memo[S][X];
  if (X == 0) return (S + 1);
  if (S == 1) return 2L;
  long val = rec(S / 2, X / 2) % (long)1000000007;
  if (S >= 1 && X >= 1)
    val += (rec((S - 1) / 2, (X - 1) / 2) % (long)1000000007);
  if (S >= 2) val += (rec((S - 2) / 2, X / 2) % (long)1000000007);
  return memo[S][X] = val;
}
int main(void) {
  long long N;
  cin >> N;
  cout << rec(N, N) << endl;
  return 0;
}
