#include <bits/stdc++.h>
using namespace std;
int vis[100001], sum[10001];
int main() {
  int n, i, j, k, t, a[100001], ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    vis[a[i]]++;
  }
  cin >> t;
  for (i = 1; i <= 1001; i++) sum[i] = sum[i - 1] + vis[i];
  for (i = 1; i <= 1001; i++) ans = max(ans, sum[i + t] - sum[i - 1]);
  cout << ans;
}
