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

typedef long long ll;
ll n, M = 1e9 + 7;
map<ll, ll> s;

ll f(ll p) {
	if (p < 2) return p + 1;
	if (s[p]) return s[p];
	return s[p] = (f(p / 2) + f((p - 2) / 2) + f((p - 1) / 2)) % M;
}

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