#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){

    i64 n;
    cin >> n;

    unordered_map<int,i64> m;
    m[0] = 0;
    m[1] = 1;

    function<i64(i64)> g = [&](i64 x){
        if(m.find(x) != m.end())
            return m[x];

        if(x & 1){
            return m[x] = (2 * g(x >> 1) + g((x >> 1) + 1)) % MOD;
        }else{
            return m[x] = (2 * g(x >> 1) + g((x >> 1) - 1)) % MOD;
        }
    };

    cout << g(n + 1) << endl;
    return 0;

}
