#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define i64 long long
using namespace std;

const int mo = 1e9 + 7;
i64 n;
map <i64, int> mp;

int calc(i64 n) {
	if (mp.count(n)) return mp[n];
	return mp[n] = ((calc(n >> 1) + calc((n - 1) >> 1)) % mo + calc((n - 2) >> 1)) % mo;
}

int main() {
	scanf("%lld", &n);
	mp[0] = 1;
	mp[1] = 2;
	printf("%d", calc(n));
	return 0;
}
