#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int ll_MAX = 1e15;
long long int fast_expo(long long int x, long long int p) {
  if (p == 0)
    return 1;
  else if (p % 2 == 0) {
    long long int t = fast_expo(x, p / 2) % MOD;
    return (t * t) % MOD;
  } else
    return (x * (fast_expo(x, p - 1)) % MOD) % MOD;
}
long long int invMod(long long int num) {
  return fast_expo(num, MOD - 2) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int t_c;
  t_c = 1;
  for (long long int t_i = 0; t_i < t_c; ++t_i) {
    long long int n;
    cin >> n;
    long long int arr[n], cnt[1005]{}, pre[1005]{};
    for (auto &i : arr) {
      cin >> i;
      cnt[i]++;
    }
    for (long long int i = 1; i < 1005; ++i) {
      pre[i] = pre[i - 1] + cnt[i];
    }
    long long int t;
    cin >> t;
    long long int ans = 0;
    for (long long int i = 0; i <= 1005; ++i) {
      if (i + t + 1 < 1005) {
        ans = max(ans, pre[i + t + 1] - pre[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
