#include <bits/stdc++.h>
using namespace std;

int main() {
	int64_t n, mod = 1e9 + 7;
	cin >> n;
	map<int64_t, int64_t> mp;
	function<int64_t(int64_t)> f = [&](int64_t a) {
		if (a < 0) {
			return int64_t(0);
		}
		if (mp[a]) {
			return mp[a];
		}
		return mp[a] = (f(a / 2) + f((a - 1) / 2) + f(a / 2 - 1)) % mod;
	};
	mp[0] = 1;
	cout << f(n) << endl;
	return 0;
}