#include<bits/stdc++.h>
#define LL long long
#define MOD (1000000007)
using namespace std;

LL n;
map<pair<LL,LL>,int>f;

int DFS(LL u,LL v)
{
	if (!v) return 1;
	if (f[make_pair(u,v)]) return f[make_pair(u,v)];
	int ans=0;
	(ans+=DFS(u>>1,v>>1))%=MOD;
	(ans+=DFS((u-1)>>1,(v-1)>>1))%=MOD;
	if (v>=2) (ans+=DFS(u>>1,(v-2)>>1))%=MOD;
	return f[make_pair(u,v)]=ans;
}

int main()
{
	cin>>n;
	cout<<DFS(n,n)<<endl;
}