#include <iostream>
#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9+7;
map<long long,long long> dp;
long long ans(long long x){
    if(dp[x]){
        return dp[x];
    }
    
    return dp[x] = ((ans(x/2)+ans((x-1)/2))%MOD+ans((x-2)/2))%MOD;
}
int main()
{
    long long n;
    cin>>n;
    dp[0] = 1;
    dp[1] = 2;
    cout<<ans(n)<<endl;
}