#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


typedef long long ll;
ll MOD = 1000000007;
ll N;
//-----------------------------------------------------------------
ll solve(ll n) {
	set<int> cnt;
	rep(i, 0, n + 1) {
		int j = n - i;
		if (i > j) break;
		cnt.insert(i^j);
	}

	return cnt.size();
}

map<ll, ll> memo;
ll a(ll n) {
	if (0 < memo[n]) return memo[n];

	if (n < 2) {
		if (n < 1)
			return memo[n] = 1;
		else
			return memo[n] = 3;
	} else {
		if (n % 2 == 0) {
			if (n == 2)
				return memo[n] = 4;
			else
				return memo[n] = (a(n / 2 - 2) + 2 * a(n / 2 - 1) + 2) % MOD;
		}
		else {
			return memo[n] = (2 * a((n - 3) / 2) + a((n - 1) / 2) + 2) % MOD;
		}
	}
}

int main() {
	cin >> N;
	cout << (a(N - 1) + 1) % MOD << endl;
}