// review
#include <iostream>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

ll n;
map<ll, ll> m;
ll dfs(ll n) {
  if (m[n] != 0) {
    return m[n];
  }
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return 2;
  }
  return m[n] = (dfs(n/2) + dfs((n-1)/2) + dfs((n-2)/2)) % MOD;
}

void solve() {
  cout << dfs(n) << endl;
}

int main() {
  cin >> n;
  solve();
}
