#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> P;
const int MOD=1e9+7;
map<ll,ll> dp;ll n;

ll dfs(ll x)
{
	if(dp.count(x)) return dp[x];
	return dp[x]=(dfs(x>>1)+dfs((x-1)>>1)+dfs((x-2)>>1))%MOD;
}

int main()
{
	scanf("%lld",&n);
	dp[0]=1;dp[1]=2;
	printf("%lld",dfs(n));
	return 0;
}