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

typedef long long ll;
ll n, M = 1e9 + 7;
map<ll, ll> d;
ll f(ll p) {
	if (p == 0) return 1;
	if (p == 1) return 2;
	if (p == 2) return 4;
	if (d[p]) return d[p];
	if (p&1) return d[p] = (2 * f(p / 2) + f(p / 2 - 1)) % M;
	else return d[p] = (f(p / 2) + 2 * f(p / 2 -1)) % M;
}
int main()
{
	cin >> n;
	cout << f(n);
    return 0;
}
