#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main()
{
    ll N; cin >> N;

    auto dp = map<ll, ll>();
    const function<ll(ll)> f = [&](const ll N)
    {
        if (N == 0) return 1LL;
        if (N == 1) return 2LL;

        if (dp.count(N)) return dp[N];

        return dp[N] = (f(N/2) + f((N-1)/2) + f((N-2)/2)) % int(1e9+7);
    };

    cout << f(N) << endl;
}
