#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long t = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) {
      t++;
    }
  }
  long long u = 0;
  vector<long long> c(t);
  c[0] = a[0];
  vector<long long> d(t);
  d[0] = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) {
      u++;
      c[u] = a[i];
      d[u] = 1;
    } else {
      d[u]++;
    }
  }
  long long na = 0;
  long long ko = t - 1;
  while (k != 0 && na != ko) {
    if (d[na] >= d[ko]) {
      if (d[ko] * (c[ko] - c[ko - 1]) <= k) {
        d[ko - 1] += d[ko];
        k -= (d[ko] * (c[ko] - c[ko - 1]));
        ko--;
      } else {
        long long y = k / d[ko];
        c[ko] -= y;
        k = 0;
      }
    } else {
      if (d[na] * (c[na + 1] - c[na]) <= k) {
        d[na + 1] += d[na];
        k -= (d[na] * (c[na + 1] - c[na]));
        na++;
      } else {
        long long y = k / d[na];
        c[na] += y;
        k = 0;
      }
    }
  }
  cout << (c[ko] - c[na]);
  return 0;
}
