#include <bits/stdc++.h>
using namespace std;
void Debug() { cout << '\n'; }
template <class FIRST, class... REST>
void Debug(FIRST arg, REST... rest) {
  cout << arg << " ";
  Debug(rest...);
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  if (!v.empty()) {
    for (int i = int(0); i < int((int)(v).size() - 1); i++) out << v[i] << ", ";
    out << v.back();
  }
  out << "]";
  return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& v) {
  out << "(" << v.first << ", " << v.second << ")";
  return out;
}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const long long mod = 1000000007;
const int inf = 1 << 29;
const long long linf = 1LL << 60;
const double PI = 3.14159265358979323846;
long long N;
long long dp[50][2][2][2];
int compare(int at, bool now, bool before) {
  int nat = (N & (1LL << at)) ? 1 : 0;
  if (before == false) {
    if (nat == 0 && now == 1)
      return 1;
    else
      return 0;
  } else {
    if (nat == 1 && now == 0)
      return 0;
    else
      return 1;
  }
}
void solve() {
  cin >> N;
  long long D = 0;
  while (N >= (1LL << D)) D++;
  dp[0][0][0][0] = 1;
  for (int i = int(0); i < int(D); i++) {
    for (int j = int(0); j < int(2); j++) {
      for (int k = int(0); k < int(2); k++) {
        for (int l = int(0); l < int(2); l++) {
          if (!dp[i][j][k][l]) continue;
          if (j == 0) {
            dp[i + 1][0][compare(i, 0, k)][compare(i, 0, l)] =
                (dp[i + 1][0][compare(i, 0, k)][compare(i, 0, l)] +
                 long long(dp[i][j][k][l])) %
                mod;
            dp[i + 1][0][compare(i, 1, k)][compare(i, 1, l)] =
                (dp[i + 1][0][compare(i, 1, k)][compare(i, 1, l)] +
                 long long(dp[i][j][k][l])) %
                mod;
            dp[i + 1][1][compare(i, 0, k)][compare(i, 0, l)] =
                (dp[i + 1][1][compare(i, 0, k)][compare(i, 0, l)] +
                 long long(dp[i][j][k][l])) %
                mod;
          } else if (j == 1) {
            dp[i + 1][0][compare(i, 0, k)][compare(i, 1, l)] =
                (dp[i + 1][0][compare(i, 0, k)][compare(i, 1, l)] +
                 long long(dp[i][j][k][l])) %
                mod;
            dp[i + 1][1][compare(i, 1, k)][compare(i, 0, l)] =
                (dp[i + 1][1][compare(i, 1, k)][compare(i, 0, l)] +
                 long long(dp[i][j][k][l])) %
                mod;
            dp[i + 1][1][compare(i, 0, k)][compare(i, 1, l)] =
                (dp[i + 1][1][compare(i, 0, k)][compare(i, 1, l)] +
                 long long(dp[i][j][k][l])) %
                mod;
          }
        }
      }
    }
  }
  cout << dp[D][0][0][0] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(20);
  srand((unsigned int)time(NULL));
  solve();
  return 0;
}
