#include <bits/stdc++.h>

using namespace std;

const int P = 1000000007;

map<pair<long long, long long>, int> dp;

int calc(long long u, long long v) {
	if(v < 0) {
		return 0;
	}
	if(v == 0) {
		return 1;
	}
	if(dp.count({ u, v })) {
		return dp[{ u, v }];
	}
	int ret = 0;
	ret = (ret + calc(u >> 1, v >> 1)) % P;
	ret = (ret + calc((u - 1) >> 1, (v - 1) >> 1)) % P;
	ret = (ret + calc((u - 1) >> 1, (v - 2) >> 1)) % P;
	return dp[{ u, v }] = ret;
}

int main() {
	long long n;
	cin >> n;

	cout << calc(n, n) << '\n';

	return 0;
}
