#include <bits/stdc++.h>
using namespace std;
int a[1001], sum[1001];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    memset(a, 0, sizeof(a));
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < n; i++) {
      int tmp;
      scanf("%d", &tmp);
      a[tmp]++;
    }
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= 1000; i++) {
      sum[i] = sum[i - 1] + a[i];
    }
    int ans = -1;
    for (int i = 1000; i >= t + 1; i--) {
      sum[i] -= sum[i - t - 1];
      ans = max(ans, sum[i]);
    }
    ans = max(ans, sum[t]);
    printf("%d\n", ans);
  }
}
