#include <iostream>
#include <map>
using namespace std;

long long N;
int mod = 1e9 + 7;
map<long long, int> mp;

int sum(long long n) {
    auto itr = mp.find(n);
    if (itr != mp.end()) return (*itr).second;
    
    if (n % 2) {
        return mp[n] = (2ll * sum(n / 2) + sum(n / 2 - 1)) % mod;
    } else {
        return mp[n] = (2ll * sum(n / 2 - 1) + sum(n / 2)) % mod;
    }
}

int main() {
    mp[0] = 1; mp[1] = 2;
    cin >> N;
    cout << sum(N) << endl;
}