#include <bits/stdc++.h>
int dp[30][(30 * (30 - 1) / 2) + 1][30];
bool bitok[30];
int main() {
  int i, j, k;
  int n, m;
  while (scanf("%d", &n) == 1) {
    int N = 0;
    while (1 << N <= n) N++;
    int M = N * (N - 1) / 2;
    int ans = 1;
    int high = n + 1;
    while (high) {
      int lowbit = high & -high;
      int low = high - lowbit;
      for (j = 0; j <= M; j++) {
        for (k = 0; k < N && k <= j; k++) {
          dp[0][j][k] = 0;
        }
      }
      for (i = 0; i < N; i++) {
        int b = 1 << (N - i - 1);
        if (b < lowbit || (b & low)) {
          bitok[i] = 1;
          if (!low) dp[0][i][i] = 1;
        } else {
          bitok[i] = 0;
        }
      }
      for (i = 0; i < N; i++) {
        if (bitok[i]) {
          dp[0][i][i] = 1;
          break;
        }
      }
      for (i = 1; i < N; i++) {
        for (j = 0; j <= M; j++) {
          for (k = 0; k < N; k++) {
            dp[i][j][k] = 0;
            if (!bitok[k]) continue;
            for (int p = 0; p < k; p++) {
              if (!bitok[p]) continue;
              int x = j - k - (1 << (N - k - 1) >= lowbit ? -1 : 0);
              if (x >= 0) dp[i][j][k] += dp[i - 1][x][p];
              while (dp[i][j][k] >= 1000000007) dp[i][j][k] -= 1000000007;
            }
          }
        }
      }
      for (m = 1; m <= N; m++) {
        int sum_max = ((N - 1) + (N - m)) * m / 2;
        if (low) {
          int tt = 0;
          while (tt < N && !bitok[tt]) tt++;
          sum_max -= N - tt - 1;
          sum_max += __builtin_ctz(lowbit);
        }
        for (i = 0; i <= sum_max; i++) {
          int q = sum_max - i;
          int mult = 1;
          while (q--) mult = mult * 2 % 1000000007;
          for (j = 0; j < N; j++) {
            ans += ((long long)dp[m - 1][i][j] * mult) % 1000000007;
            while (ans >= 1000000007) ans -= 1000000007;
          }
        }
      }
      high = low;
    }
    printf("%d\n", ans);
  }
}
