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 <map>
using namespace std;

map<long long, long long>M[63];
long long power3[63], N, power2[63], mod = 1000000007, cnts;

long long dfs(long long pos, long long sum) {
	if (sum < 0) return 0;
	if (pos < 0) return 1;
	if (sum >= power2[pos]) return power3[pos + 1];
	if (M[pos][sum] >= 1) return M[pos][sum] - 1;
	long long res = 0; cnts++;
	res += dfs(pos - 1, sum - (0LL << pos));
	res += dfs(pos - 1, sum - (1LL << pos));
	res += dfs(pos - 1, sum - (2LL << pos));
	res %= mod;
	M[pos][sum] = res + 1;
	return res;
}

int main() {
	cin >> N;
	power3[0] = 1; for (int i = 1; i < 63; i++) power3[i] = (power3[i - 1] * 3) % mod;
	power2[0] = 2; for (int i = 1; i < 63; i++) power2[i] = power2[i - 1] + (2LL << i);
	cout << dfs(60, N) << endl;
	return 0;
}