// 基本テンプレート (縮小版)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
int dp[62][3];

signed main() {
    cin >> N;
    dp[0][0] = 1;
    rep(i,0,61) rep(c,0,3) rep(x,0,2) rep(y,x,2) {
        int val = (N >> i & 1) - c - x - y;
        (dp[i+1][(1-val)/2] += dp[i][c]) %= MOD;
    }
    cout << dp[61][0] << endl;
    return 0;
}