#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int cnt[maxn];
map<ll, ll> M;
int f(int x)
{
	unordered_set<int> S;
	for(int i = 0, j = x; i <= j; ++i, --j)
		S.insert(i ^ j);
	return S.size();
}
ll F(ll x)
{
	//a(2k) = 2*a(k-1) + a(k); a(2k+1) = 2*a(k) + a(k-1)
	if(x == 0) return 1;
	if(x == 1) return 2;
	if(M.find(x) == M.end())
	{
		ll mid = x >> 1;
		if(x & 1) return M[x] = (2 * F(mid) + F(mid - 1)) % mod;
		else return M[x] = (2 * F(mid - 1) + F(mid)) % mod;
	}
	return M[x];
}
int main()
{
	/*
	const int n = 1422;
	for(int i = 0; i <= n; ++i) cnt[i] = f(i);
	for(int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1], cout << i << ' ' << cnt[i] << endl;
	*/
	ll n;
	cin >> n;
	cout << F(n) << endl;
	return 0;
}