#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

map<LL,LL> ma;

LL f(LL N){
    if(ma[N]) return ma[N];
    if(N==0) return 1;
    if(N==1) return 2;
    return ma[N]=(f(N/2)+f((N-1)/2)+f((N-2)/2))%mod;
}

int main(){
    LL N;
    cin >> N;
    cout << f(N) << endl;
    return 0;
}