#include <bits/stdc++.h>
using namespace std;
int b[1006];
int main() {
  int n;
  cin >> n;
  for (int i = 1, a; i <= n; ++i) {
    cin >> a, b[a]++;
  }
  int t;
  cin >> t;
  t++;
  for (int i = 1; i <= t; ++i) b[i] += b[i - 1];
  int mx = b[t];
  for (int i = t + 1; i <= 1004; ++i) {
    b[i] += b[i - 1];
    mx = max(mx, b[i] - b[i - t]);
  }
  cout << mx << endl;
}
