#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
const long long mod = 1000000007;
long long N;
long long dp[20][3];
inline void add(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
signed main() {
  cin >> N;
  dp[20][0] = 1;
  for (long long i = 19; i >= 0; i--) {
    for (long long j = 0; j <= 2; j++) {
      for (long long a = 0; a <= 2; a++) {
        long long nj = j * 2 + (N >> i & 1) - a;
        if (nj < 0) continue;
        if (nj > 2) nj = 2;
        add(dp[i][nj], dp[i + 1][j]);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (3); i++) add(ans, dp[0][i]);
  cout << ans << endl;
  return 0;
}
