#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
map<int,int>a;
int dfs(int x){
    return a[x]?a[x]:a[x]=(dfs(x/2)+dfs((x-1)/2)+dfs((x-2)/2))%mod;
}
signed main(){
    a[0]=1;
    a[1]=2;
    int n;
    cin>>n;
    cout<<dfs(n)<<endl;
	return 0;
}