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<iostream>
#include<vector>
using namespace std;

#define MOD (1000000007)

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n; cin >> n;
	vector<int> ns{};
	while (n) {
		ns.push_back(n % 2);
		n >>= 1;
	}
	// n>>iと (a>>i)+(b>>i)の差が0,1,2の場合の場合の数をc[0],c[1],c[2]とする。
	// n,a,bの上からi+1桁目の数をn',a',b'と書くことにすると、
	// n'=0,1, a'+b'=0,1,2のときの遷移を考えればよい。
	// 結果は
	// c[2] = 3*c[2]+(1+n')*c[1]
	// c[n']+=c[1-n']
	// となる

	long long c0{ 1 };
	long long c1{ 0 };
	long long c2{ 0 };
	while (ns.size()) {
		int ni = ns.back(); ns.pop_back();
		c2 *= 3;
		c2 += (1 + ni)*c1;
		c2 %= MOD;
		if (ni) {
			c1 += c0;
			c1 %= MOD;
		}
		else {
			c0 += c1;
			c1 %= MOD;
		}
	}
	long long ans = (c0 + c1 + c2) % MOD;

	cout<<ans<<endl;

	return 0;
}