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 <unordered_map>
#define int long long
using namespace std;

int power[60];
unordered_map<int, int> memo;

int dfs(int n) {	
	if (n <= 1) { return 0; }
	if (memo.find(n) != memo.end()) { return memo[n]; }
	
	int i;
	for (i = 0; (1LL << i) <= n; i++); i--;
	int diff = n - (1LL << i) - (1LL << (i-1));
	int ret = power[i - 1] + dfs(n - (1LL << i)) + dfs(n - (1LL << (i-1))) - dfs(diff) * 2;
	
	return memo[n] = ret % 1000000007;
}

signed main() {
	power[0] = 1;
	for (int i = 1; i < 60; i++) {
		power[i] = power[i - 1] * 3;
		power[i] %= 1000000007;
	}
	
	int n;
	cin >> n;
	cout << dfs(n + 2) << endl;
	return 0;
}