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 <cstdio>
#include <map>
const long long MOD = 1000000007;
long long N, O, pow3[61];
std::map < long long, long long > ans[61];
long long F(long long n, int w)
{
	if (w == -1)
		return 1;
	if (n >= (4LL << w) - 2)
		return pow3[w + 1];
	auto it = ans[w].find(n);
	if (it != ans[w].end())
		return it -> second;
	long long r = 0;
	for (long long i = 0; i <= 2 && i <= n >> w; i++)
		r += F(n - (i << w), w - 1);
	return ans[w][n] = r % MOD;
}
int main()
{
	scanf("%lld", &N);
	pow3[0] = 1;
	for (int i = 1; i <= 60; i++)
		pow3[i] = pow3[i - 1] * 3 % MOD;
	printf("%lld\n", F(N, 60));
	return 0;
}
