You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.

Constraints

* 1≦N≦10^{18}

Input

The input is given from Standard Input in the following format:


N


Output

Print the number of the possible pairs of integers u and v, modulo 10^9+7.

Examples

Input

3


Output

5


Input

1422


Output

52277


Input

1000000000000000000


Output

787014179
#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;
}
