#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;
}
