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;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int cnt[maxn];
map<ll, ll> M;
int f(int x)
{
	unordered_set<int> S;
	for(int i = 0, j = x; i <= j; ++i, --j)
		S.insert(i ^ j);
	return S.size();
}
ll F(ll x)
{
	//a(2k) = 2*a(k-1) + a(k); a(2k+1) = 2*a(k) + a(k-1)
	if(x == 0) return 1;
	if(x == 1) return 2;
	if(M.find(x) == M.end())
	{
		ll mid = x >> 1;
		if(x & 1) return M[x] = (2 * F(mid) + F(mid - 1)) % mod;
		else return M[x] = (2 * F(mid - 1) + F(mid)) % mod;
	}
	return M[x];
}
int main()
{
	/*
	const int n = 1422;
	for(int i = 0; i <= n; ++i) cnt[i] = f(i);
	for(int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1], cout << i << ' ' << cnt[i] << endl;
	*/
	ll n;
	cin >> n;
	cout << F(n) << endl;
	return 0;
}