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 mod 1000000007
map<long long,long long> dp[65];
long long solve(long long n,int b)
{
	if (!n || b==-1)
	return 1;
	int m=60;
	while (!(n&(1LL<<m)))
	m--;
	b=min(b,m);
	if (dp[b].count(n))
	return dp[b][n];
	long long ans=solve((1LL<<m)-1,b);
	if (m<=b)
	ans=(ans+solve(n^(1LL<<m),m-1))%mod;
	if (m<=b+1)
	{
		for (int i=m-1;i>=0;i--)
		ans=(ans+solve(n^(1LL<<m),i-1))%mod;
	}
	return dp[b][n]=ans;
}
int main()
{
	long long n;
	scanf("%lld",&n);
	printf("%lld",solve(n,60));
}