#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
  char ch, fu = 0;
  for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') fu = 1, ch = getchar();
  for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
  if (fu) v = -v;
}
const int MO = 1e9 + 7;
int K, b[666];
long long f[33][33][2], ans, p2[666];
int main() {
  cin >> K;
  for (int i = 0; i <= 29; ++i) b[i] = (K >> i) & 1;
  f[30][0][0] = 1;
  p2[0] = 1;
  for (int i = 1; i <= 30; ++i) p2[i] = p2[i - 1] * 2 % MO;
  for (int i = 30; i >= 1; --i)
    for (int j = 0; j <= 30; ++j) {
      if (f[i][j][0]) {
        if (b[i - 1]) {
          (f[i - 1][j + 1][0] += f[i][j][0]) %= MO;
        }
        if (j == 0) {
          if (b[i - 1])
            (f[i - 1][j][1] += f[i][j][0]) %= MO;
          else
            (f[i - 1][j][0] += f[i][j][0]) %= MO;
        } else {
          if (b[i - 1]) {
            (f[i - 1][j][1] += f[i][j][0] * p2[j - 1]) %= MO;
            (f[i - 1][j][0] += f[i][j][0] * p2[j - 1]) %= MO;
          } else {
            (f[i - 1][j][0] += f[i][j][0] * p2[j - 1]) %= MO;
          }
        }
      }
      if (f[i][j][1]) {
        (f[i - 1][j + 1][1] += f[i][j][1]) %= MO;
        (f[i - 1][j][1] += f[i][j][1] * p2[j]) %= MO;
      }
    }
  ans = 0;
  for (int i = 0; i <= 30; ++i)
    for (int j = 0; j <= 1; ++j) (ans += f[0][i][j]) %= MO;
  cout << ans << endl;
  return 0;
}
