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

typedef long long ll;
const ll mod = 1e9 + 7;
map<ll, ll>mp;

inline ll f(ll x) {
	if (mp[x])return mp[x];
	return mp[x] = (f(x / 2) + f((x - 1) / 2) + f((x - 2) / 2)) % mod;
}

int main() {
	ll n; cin >> n;
	mp[0] = 1, mp[1] = 2;
	cout << f(n) << endl;

	return 0;
}