#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

map<long long, long long>Map[64];
long long N, mod = 1000000007;

long long solve(int bit, long long rem) {
	if (bit >= 0) rem = min(rem, (4LL << bit) - 2LL);
	if (rem < 0) return 0;
	if (bit == -1) return 1;
	if (Map[bit][rem] >= 1) return Map[bit][rem] - 1;

	long long v1 = solve(bit - 1, rem);
	long long v2 = solve(bit - 1, rem - (1LL << bit));
	long long v3 = solve(bit - 1, rem - (2LL << bit));
	long long D = (v1 + v2 + v3) % mod;
	Map[bit][rem] = D + 1;
	return D;
}

int main() {
	cin >> N;
	cout << solve(60, N) << endl;
	return 0;
}