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<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
int p=0,np=1,dp[2][2][2];
// 是否顶上界,进位 
ll n;
int main(){
	scanf("%lld",&n);
	dp[np][0][0]=1;
	for(int i=0;n>=(1ll<<i);i++,swap(p,np)){
		int d=!!(n&(1ll<<i));
		memset(dp[p],0,sizeof(dp[p]));
		for(int j=0;j<2;++j)
			for(int k=0;k<2;++k)if(dp[np][j][k])
				for(int s=0;s<2;++s)
					for(int t=0;t<2;++t){
						if(s==1&&t==0)continue;
						int x=s+t+k;
						int nj=x%2>d?1:(x%2<d?0:j);
						int nk=x/2;
//						printf("[%d,%d,%d]->[%d,%d,%d]\n",i,j,k,i+1,nj,nk);
						dp[p][nj][nk]+=dp[np][j][k];
						if(dp[p][nj][nk]>=mod)dp[p][nj][nk]-=mod;
					}
	}
	printf("%d",dp[np][0][0]);
}