#include<cstdio>
#include<iostream>
#include<map>
#define ll long long
#define mo 1000000007
using namespace std;
ll n;
map<ll,ll>a;
ll work(ll n)
{
	if(!n)return 1;
	if(n==1)return 2;
	if(a[n])return a[n];
	return a[n]=(work(n>>1)+work((n-1)>>1)+work((n-2)>>1))%mo;
}
int main()
{
	cin>>n;
	cout<<work(n)<<endl;
}