#include<cstdio>
#include<map>
#define ll long long
using namespace std;
const int mod=1e9+7;
map<ll,ll> DP;
ll DFS(ll x){
    if(DP[x])return DP[x];
    return DP[x]=(DFS(x>>1)+DFS(x-1>>1)+DFS(x-2>>1))%mod;
}
int main(){
	//freopen("a.in","r",stdin);
    ll n;scanf("%lld",&n);
    DP[0]=1;DP[1]=2;
    ll res=DFS(n)%mod;
    printf("%lld\n",res);
    return 0;
}
