#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll (i)=(0);(i)<(ll)(n);++(i))
typedef pair<int, int> P;
using ll = long long;
 
map< pair<ll, ll>, ll > memo;
const ll mod = 1000000007LL;
 
ll func(ll S, ll X) {
 
    if (S < 0 or X < 0) return 0;
 
    if (S == 0 and X >= 0) {
        return 1;
    }
    else if (S == 1 and X == 0) {
        return 1;
    }
    else if (S == 1 and X > 0) {
        return 2;
    }
 
    if (memo.count({S, X})) {
        return memo[{S, X}];
    }
 
    return memo[{S, X}] = (func(S/2, X/2) + func((S-1)/2, (X-1)/2) + func((S-2)/2, X/2)) % mod;
}
 
int main() {
    ll N;
    cin >> N;
    cout << func(N, N) << endl;
}