#include using namespace std; const unsigned mod = 1000000007; unsigned long long N; unsigned dp[66][16]; bool vis[66][16]; unsigned solve(int digit, int fx, int fy, int f10, int f11) { if (digit == -1) return f10 && f11 ? 1 : 0; int h = fx + fy * 2 + f10 * 4 + f11 * 8; if (vis[digit][h]) return dp[digit][h]; unsigned ret = solve(digit - 1, fx || ((N >> digit) & 1), fy || ((N >> digit) & 1), f10, f11); bool vx = fy == 1 || ((N >> digit) & 1); bool vy = fx == 1 || ((N >> digit) & 1); if (vy) ret += solve(digit - 1, fx || ((N >> digit) & 1), fy, 1, f11); if (vx) ret += solve(digit - 1, fx, fy || ((N >> digit) & 1), 1, f11); if (vx && vy && f10) ret += solve(digit - 1, fx, fy, 1, 1); while (ret >= mod) ret -= mod; vis[digit][h] = true; dp[digit][h] = ret; return ret; } int main() { cin >> N; unsigned ret = solve(60, 0, 0, 0, 0); cout << 1ull * ret * (mod / 2 + 1) % mod << '\n'; return 0; }