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 ll int64_t

// dp digit
// SUM=a+b, XOR=a^b
// SUM=((a&b)<<1)+XOR
//    =AND*2+XOR
//    =OR+AND (AND+XOR=OR)

const ll mod=1e9+7;
ll n,dp[65][2][2];

ll dfs(int i,int carry,bool ok){
	if(i==60) return carry==0&&ok;
	ll& res=dp[i][carry][ok];
	if(~res) return res;
	res=0;
	ll curbit=n>>i&1ll;
	for(int a=0;a<2;++a)
		for(int b=0;b<=a;++b){
			int bit=(a+b+carry)&1;
			bool isOk=ok;
			if(bit>curbit) isOk=false;
			if(bit<curbit) isOk=true;
			(res+=dfs(i+1,(a+b+carry)/2,isOk))%=mod;
		}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	memset(dp,-1,sizeof dp);
	cout<<dfs(0,0,true)<<'\n';
}

