#include<bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;
typedef pair<long long, long long> Pairs;

long long n;
map<long long,int> dp;

inline void Add(int &x, int a) {
    x += a; while (x >= MOD) x -= MOD;
}
inline int Calc(long long v)
{
    if (v < 0) return 0;
    if (!v) return 1;
    if (dp.count(v)) return dp[v];
    int res = 0;
    Add(res, Calc(v >> 1));
    Add(res, Calc((v - 1) >> 1));
    if (v >= 2) Add(res, Calc((v - 2) >> 1));
    return dp[v] = res;
}

int main(void) {
    //freopen("1.in", "r", stdin);
    cin >> n;
    cout << Calc(n) << endl;
    return 0;
}