#include <bits/stdc++.h>
using namespace std;
const int Mo=1000000007;
map <long long,int> f;
inline int solve(long long n) {
    if(f.count(n)) return f[n];
    return f[n]=((solve(n/2)+solve((n-1)/2))%Mo+solve((n-2)/2))%Mo;
}
int main() {
    f[0]=1,f[1]=2;
    long long n;
    cin>>n;
    cout<<solve(n);
    return 0;
}