#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int f[31][31][2], p2[31];
const int P = 1000000007;
void solve() {
  cin >> n;
  int lim = (31 - __builtin_clz(n));
  f[lim + 1][0][1] = 1;
  p2[0] = 1;
  for (int i = (1), iend = (lim + 1); i <= iend; ++i) p2[i] = p2[i - 1] * 2 % P;
  for (int i = (lim + 1), iend = (1); i >= iend; --i)
    for (int j = (0), jend = (31); j <= jend; ++j) {
      if (f[i][j][0]) {
        f[i - 1][j + 1][0] = (f[i - 1][j + 1][0] + f[i][j][0]) % P;
        f[i - 1][j][0] = (f[i - 1][j][0] + f[i][j][0] * 1ll * p2[j]) % P;
      }
      if (f[i][j][1]) {
        int od = (j ? p2[j - 1] : 0), ev = (j ? p2[j - 1] : 1);
        if (n & (1 << i - 1))
          f[i - 1][j + 1][1] = (f[i - 1][j + 1][1] + f[i][j][1]) % P,
                       f[i - 1][j][1] =
                           (f[i - 1][j][1] + f[i][j][1] * 1ll * od) % P,
                       f[i - 1][j][0] =
                           (f[i - 1][j][0] + f[i][j][1] * 1ll * ev) % P;
        else
          f[i - 1][j][1] = (f[i - 1][j][1] + f[i][j][1] * 1ll * ev) % P;
      }
    }
  long long res = 0;
  for (int i = (0), iend = (30); i <= iend; ++i)
    res = (res + f[0][i][0] + f[0][i][1]) % P;
  cout << res << endl;
}
signed main() { solve(); }
