#include <bits/stdc++.h>
using namespace std;
const long long MN = 1e5 + 7;
long long a[MN], n, k;
vector<pair<long long, long long> > v;
signed main() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long cnt = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1])
      cnt++;
    else {
      v.push_back({a[i - 1], cnt});
      cnt = 1;
    }
  }
  v.push_back({a[n - 1], cnt});
  n = v.size();
  for (long long i = 0; i < n; i++) {
    cerr << v[i].first << ' ' << v[i].second << endl;
  }
  long long pi = 0, qi = n - 1, po = v[0].first, qo = v[n - 1].first,
            pres = v[0].second, sufs = v[n - 1].second;
  while (po < qo && k >= min(pres, sufs)) {
    if (pres < sufs) {
      if (k >= pres * (v[pi + 1].first - po)) {
        k -= (v[pi + 1].first - po) * pres;
        pres += v[pi + 1].second;
        po = v[pi + 1].first;
        pi++;
      } else {
        po += k / pres;
        k = 0;
        break;
      }
    } else {
      if (k >= sufs * (qo - v[qi - 1].first)) {
        k -= (qo - v[qi - 1].first) * sufs;
        sufs += v[qi - 1].second;
        qo = v[qi - 1].first;
        qi--;
      } else {
        qo -= k / sufs;
        k = 0;
        break;
      }
    }
  }
  if (po > qo) po = qo;
  cout << qo - po;
}
