#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
map<long long, long long> f;
long long Dp(long long x) {
  if (f[x]) return x;
  return (f[x] = (Dp(x / 2) + Dp((x - 1) / 2) + Dp((x - 2) / 2)) % mod);
}
int main() {
  long long n;
  cin >> n;
  f[0] = 1;
  f[1] = 2;
  cout << Dp(n) << endl;
  return 0;
}
