#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
constexpr int NUM_BITS = 60;
constexpr int64 P = 1000000007;
struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x;
    x %= P;
    if (x < 0) x += P;
    return x;
  }

 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this);
    r += o;
    return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this);
    r -= o;
    return r;
  }
  inline FiniteField operator*(FiniteField o) const {
    FiniteField r(*this);
    r *= o;
    return r;
  }
  inline FiniteField operator/(FiniteField o) const {
    FiniteField r(*this);
    r /= o;
    return r;
  }
  inline void operator+=(FiniteField o) { x = (x + o.x) % P; }
  inline void operator-=(FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*=(FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2;
    while (p) {
      if (p % 2) {
        *this *= o;
      }
      o *= o;
      p /= 2;
    }
  }
};
ostream& operator<<(ostream& s, const FiniteField& v) {
  s << v.Value();
  return s;
}
FiniteField Power(FiniteField x, int p) {
  if (p < 0) return FiniteField(1) / Power(x, -p);
  FiniteField value = 1;
  while (p) {
    if (p % 2) value *= x;
    x *= x;
    p /= 2;
  }
  return value;
}
template <typename T>
vector<vector<vector<T>>> Make3DVector(int d1, int d2, int d3,
                                       T default_value) {
  return vector<vector<vector<T>>>(
      d1, vector<vector<T>>(d2, vector<T>(d3, default_value)));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64 n;
  cin >> n;
  auto solve_d_fn = [](int64 n, int num_digits) -> FiniteField {
    if (DEBUG) cout << "solve_d_fn: " << num_digits << endl;
    auto dp = Make3DVector(num_digits + 1, 2, 2, FiniteField(0));
    if ((n >> num_digits) > 0) {
      dp[0][1][0] = 1;
    } else {
      dp[0][0][0] = 1;
    }
    for (int k = 0; k < num_digits; k++) {
      for (int i = 1; i + k <= num_digits; i++) {
        bool greater = false;
        if (((n >> (num_digits - k - 1)) & 1) == 0) greater = true;
        bool less = false;
        for (int b = num_digits - k - 1; b >= num_digits - k - i + 1; b--) {
          if (((n >> (b - 1)) & 1) == 1) {
            less = true;
          }
        }
        if (DEBUG) {
          cout << "k: " << k << " i: " << i << " greater: " << greater
               << " less: " << less << endl;
        }
        for (int l = 0; l < 2; l++) {
          FiniteField a = dp[k][l][0];
          FiniteField b = dp[k][l][1];
          if (l == 0) {
            if (greater) continue;
            if (i >= 2) {
              dp[k + i][less][0] += a * (i - 1) + b * (2 * i - 3);
              dp[k + i][less][1] += a + b * 2;
            } else {
              dp[k + i][less][1] += a + b;
            }
          } else {
            if (i >= 2) {
              dp[k + i][1][0] += a * (i - 1) + b * (2 * i - 3);
              dp[k + i][1][1] += a + b * 2;
            } else {
              dp[k + i][1][1] += a + b;
            }
          }
        }
      }
    }
    for (int k = 0; k <= num_digits; k++) {
      for (int l = 0; l < 2; l++) {
        for (int s = 0; s < 2; s++) {
          cout << dp[k][l][s] << " ";
        }
      }
      cout << endl;
    }
    FiniteField r = 0;
    for (int l = 0; l < 2; l++) {
      for (int s = 0; s < 2; s++) {
        r += dp[num_digits][l][s];
      }
    }
    return r;
  };
  FiniteField ans = 1;
  for (int d = 1; d <= NUM_BITS; d++) {
    FiniteField delta = solve_d_fn(n, d);
    if (DEBUG) cout << "d: " << d << " delta: " << delta << endl;
    ans += delta;
  }
  cout << ans << endl;
}
