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<stdio.h>
#include<string.h>

long long sum(long long a, long long b) {
	return (a + b) % 1000000007;
}

int main(void) {
	long long a[65][3];
	long long N,M;
	int i,j,p[64];
	long long ans;
	scanf("%lld", &N);
	M = N;
	for (i = 0; i < 64; i++) {
		p[63 - i] = M % 2;
		M = M / 2;
	}

	a[0][0] = 1; 
	a[0][1] = 0;
	a[0][2] = 0;
	for (i = 1; i < 65; i++) {
		if (p[i-1] == 0) {
			a[i][2] = (3*a[i - 1][2]+ a[i - 1][1]) % 1000000007;
			a[i][1] = a[i - 1][1];
			a[i][0] = (a[i - 1][0]+ a[i - 1][1]) % 1000000007;
		}
		else {
			a[i][2] = (3 * a[i - 1][2] + a[i - 1][1] + a[i - 1][1]) % 1000000007;
			a[i][1] = (a[i - 1][1]+ a[i - 1][0]) % 1000000007;
			a[i][0] = a[i - 1][0];
		}
		/*printf("p[%d] = %d, a[%d][0] = %lld\n	", i, p[i], i, a[i][0]);*/
	}

	ans = 0;
	ans = (a[64][0] + a[64][1] + a[64][2]) % 1000000007;

	printf("%lld\n", ans);



	return 0;
}
