#include<bits/stdc++.h>
using namespace std;
map<long long,long long>dp;
const long long md=1e9+7;
long long calc(long long x)
{
	if(dp.find(x)!=dp.end())return dp[x];
	if(x==0)return dp[0]=1;
	if(x==1)return dp[1]=2;
	return dp[x]=(calc(x/2)+calc((x-1)/2)+calc((x-2)/2))%md;
}
int main()
{
	long long n;
	scanf("%lld",&n);
	printf("%lld\n",calc(n));
	return 0;
}