#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, M=1e9+7;
map<ll, ll> m;
ll f(ll p) {
	if(p<2) return p+1;
	if(m[p]) return m[p];
	return m[p] = (p%2 ? 2*f(p/2)+f(p/2-1) : f(p/2)+2*f(p/2-1)) % M;
}

int main() {
	cin>>n;
	cout<<f(n);
	return 0;
}