#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
map<PLL, LL> memo;
LL solve(LL S, LL X) {
	if (S == 0 && X == 0) return 1;
	if (memo.find(MP(S, X)) != memo.end()) return memo[MP(S, X)];
	LL ret = solve(S / 2, X / 2);
	if (S >= 1 && X >= 1) ret = (ret + solve((S - 1) / 2, (X - 1) / 2)) % MOD;
	if (S >= 2) ret = (ret + solve((S - 2) / 2, X / 2)) % MOD;
	return memo[MP(S, X)] = ret;
}
int main() {
	LL N;
	cin >> N;
	cout << solve(N, N) << endl;
}