#include <stdio.h>
#include <algorithm>

#define MOD 1000000007

long long int N;
int dp[70][3], bit, ans;

int main()
{
	scanf("%lld", &N);

	dp[0][0] = 1;
	bit = log2(N);
	for (int i = 0; i <= bit; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (N >> (bit - i) & 1)
			{
				dp[i + 1][std::min(j * 2 + 1, 2)] += dp[i][j];
				dp[i + 1][std::min(j * 2, 2)] += dp[i][j];
				dp[i + 1][std::min(j * 2 + 1, 2)] %= MOD;
				dp[i + 1][std::min(j * 2, 2)] %= MOD;
				if ((j * 2 - 1) >= 0)
				{
					dp[i + 1][std::min(j * 2 - 1, 2)] += dp[i][j];
					dp[i + 1][std::min(j * 2 - 1, 2)] %= MOD;
				}
			}
			else
			{
				dp[i + 1][std::min(j * 2, 2)] += dp[i][j];
				dp[i + 1][std::min(j * 2, 2)] %= MOD;
				if ((j * 2 - 1) >= 0)
				{
					dp[i + 1][std::min(j * 2 - 1, 2)] += dp[i][j];
					dp[i + 1][std::min(j * 2 - 1, 2)] %= MOD;
				}
				if ((j * 2 - 2) >= 0)
				{
					dp[i + 1][std::min(j * 2 - 2, 2)] += dp[i][j];
					dp[i + 1][std::min(j * 2 - 2, 2)] %= MOD;
				}
			}
		}
	}
	ans = dp[bit + 1][0] + dp[bit + 1][1] + dp[bit + 1][2];
	ans %= MOD;

	printf("%d\n", ans);
	return 0;
}