#include <bits/stdc++.h>
const int N = 31;
const int MOD = (int)1e9 + 7;
int n;
int dp0[N][N], dp1[N][N];
inline void Ad(int &a, int b) {
  if ((a += b) >= MOD) a -= MOD;
}
int main() {
  scanf("%d", &n);
  dp1[30][0] = 1;
  for (int i = 30; i >= 1; --i) {
    for (int j = 0; j <= 30; ++j) {
      int x = (j) ? (1 << (j - 1)) : (1);
      int y = (j) ? (1 << (j - 1)) : (0);
      {
        Ad(dp0[i - 1][j + 1], dp0[i][j]);
        Ad(dp0[i - 1][j], (1LL << j) * dp0[i][j] % MOD);
      }
      {
        if ((n >> (i - 1)) & 1) {
          Ad(dp0[i - 1][j], (long long)x * dp1[i][j] % MOD);
          Ad(dp1[i - 1][j + 1], dp1[i][j]);
          Ad(dp1[i - 1][j], (long long)y * dp1[i][j] % MOD);
        } else {
          Ad(dp1[i - 1][j], (long long)x * dp1[i][j] % MOD);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= 30; ++i) {
    Ad(ans, dp0[0][i]);
    Ad(ans, dp1[0][i]);
  }
  printf("%d\n", ans);
  return 0;
}
