#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long
const int M=1000000007;
ll ans,n;

map<P,ll>dp;

ll dfs(ll s,ll x){
	
	//cout<<s<<" "<<x<<endl;
	//if(x<=1&&s<=1)return 1;
	if(dp[mp(s,x)]>0)return dp[mp(s,x)];
	if(x==0&&s==0)return dp[mp(s,x)]=1;

	ll ret=0;
	ret+=dfs(s/2,x/2);
	if(s>=1&&x>=1)ret+=dfs((s-1)/2,(x-1)/2)%M;
	if(s>=2)ret+=dfs((s-2)/2,x/2)%M;

	return dp[mp(s,x)]=ret%M;
}
int main(){
	cin>>n;
	

	cout<<dfs(n,n)<<endl;

	//cout<<ans<<endl;
	return 0;
}
