#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
map<int,int>num;
typedef long long ll;
const int N=1e6+10;
const int Mod=1e9+7;
ll cal(ll x){
    if(num[x]!=0) return num[x];
    return num[x]=(cal(x/2)+cal((x-1)/2)+cal((x-2)/2))%Mod;
}
int main(){
    num[0]=1;num[1]=2;
    ll n;
    scanf("%lld",&n);
    printf("%lld\n",cal(n));
    return 0;
}