#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
map<long long,long long> dp[65];
long long solve(long long n,int b)
{
	if (!n || b==-1)
	return 1;
	int m=60;
	while (!(n&(1LL<<m)))
	m--;
	b=min(b,m);
	if (dp[b].count(n))
	return dp[b][n];
	long long ans=solve((1LL<<m)-1,b);
	if (m<=b)
	ans=(ans+solve(n^(1LL<<m),m-1))%mod;
	if (m<=b+1)
	{
		for (int i=m-1;i>=0;i--)
		ans=(ans+solve(n^(1LL<<m),i-1))%mod;
	}
	return dp[b][n]=ans;
}
int main()
{
	long long n;
	scanf("%lld",&n);
	printf("%lld",solve(n,60));
}