#include <bits/stdc++.h>
const int MOD = 1e9 + 7, N = 30;
int n, f[N][N][2];
int calc(int n, bool isEven) { return n == 0 ? isEven : 1 << (n - 1); }
int dfs(int len, int cnt, bool lim) {
  if (len == -1) {
    return 1;
  }
  if (f[len][cnt][lim] >= 0) {
    return f[len][cnt][lim];
  }
  int up = lim ? (n >> len) & 1 : 1;
  long long ans =
      (long long)calc(cnt, true) * dfs(len - 1, cnt, lim && up == 0) % MOD;
  if (up == 1) {
    ans += dfs(len - 1, cnt + 1, lim && up == 1);
    ans +=
        (long long)calc(cnt, false) * dfs(len - 1, cnt, lim && up == 1) % MOD;
  }
  return f[len][cnt][lim] = ans % MOD;
}
int main() {
  scanf("%d", &n);
  memset(f, -1, sizeof(f));
  printf("%d\n", dfs(29, 0, true));
  return 0;
}
