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>

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> P;
#define MAX_D 64
#define MOD ((ll)1e9 + 7)
ll N,dp[MAX_D][3],res;int nxt;

int main() 
{	
	scanf("%lld",&N);
	dp[MAX_D-1][0]=1;
	for(int i=MAX_D-1;i>0;i--) 
	    for(int j=0; j <= 2; j++)
		    for(int dv=0;dv<=2;dv++) 
			{
		        nxt=j*2+((N>>(i-1))&1)-dv;
		        if (nxt<0) continue;
		        nxt=nxt>2?2:nxt;
		        (dp[i-1][nxt]+=dp[i][j])%=MOD;
		    }
	res=0;
	for (int i=0;i<=2;i++) (res+=dp[0][i])%=MOD;
	printf("%lld\n", res);
	return 0;
}