#include <bits/stdc++.h>
using namespace std;
int a[1010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0, x; i < n; i++) {
    scanf("%d", &x);
    a[x]++;
  }
  int T;
  scanf("%d", &T);
  for (int i = 2; i <= 1009; i++) {
    a[i] += a[i - 1];
  }
  int maxv = 0;
  for (int i = 1; i + T <= 1008; i++) {
    maxv = max(maxv, a[i + T] - a[i - 1]);
  }
  printf("%d\n", maxv);
  return 0;
}
