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