#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int Mod=1e9+7;
map <ll ,int > f;
int solve(ll x){
	if (f[x]) return f[x];
	return f[x]=(((solve(x/2)+solve((x-1)/2))%Mod+solve((x-2)/2))%Mod);
}
int main (){
	f[0]=1,f[1]=2;
	ll n;scanf ("%lld",&n);
	printf ("%d",solve(n));
	return 0;
}