#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(){
    ll n;
    scanf("%lld",&n);
    dp[0]=1;
    dp[1]=2;
    ll res=dfs(n)%Mod;
    printf("%lld\n",res);
}