#include <bits/stdc++.h>
using namespace std;
int f[30 + 2][30 + 2][2];
int main() {
  int n;
  scanf("%d", &n);
  f[30][0][1] = 1;
  for (int i = 30; i; i--)
    for (int j = 0; j <= 30; j++) {
      f[i - 1][j][0] = (f[i - 1][j][0] + f[i][j][0] * (1ll << j)) % 1000000007;
      f[i - 1][j + 1][0] = (f[i - 1][j + 1][0] + f[i][j][0]) % 1000000007;
      if ((n >> (i - 1)) & 1) {
        f[i - 1][j][0] =
            (f[i - 1][j][0] + (j ? 1ll << (j - 1) : 1ll) * f[i][j][1]) %
            1000000007;
        f[i - 1][j][1] =
            (f[i - 1][j][1] + (j ? 1ll << (j - 1) : 0) * f[i][j][1]) %
            1000000007;
        f[i - 1][j + 1][1] = (f[i - 1][j + 1][1] + f[i][j][1]) % 1000000007;
      } else
        f[i - 1][j][1] =
            (f[i - 1][j][1] + (j ? 1ll << (j - 1) : 1ll) * f[i][j][1]) %
            1000000007;
    }
  int ans = 0;
  for (int i = 0; i <= 30; i++)
    ans = (1ll * ans + f[0][i][0] + f[0][i][1]) % 1000000007;
  printf("%d", ans);
  return 0;
}
