#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
long long n, k;
long long F() {
  vector<long long> b = a;
  long long curl = 0, curr = n - 1;
  long long xl = b[curl], xr = b[curr];
  long long cnt = k;
  while (curl < curr) {
    if (xl == b[curl + 1])
      curl++;
    else if (xr == b[curr - 1])
      curr--;
    else {
      if (curl + 1 < n - curr) {
        if ((b[curl + 1] - xl) * (curl + 1) <= cnt) {
          cnt -= (b[curl + 1] - xl) * (curl + 1);
          curl++;
          xl = b[curl];
        } else {
          long long tmp = (curl + 1);
          xl += cnt / tmp;
          return xr - xl;
        }
      } else {
        if ((xr - b[curr - 1]) * (n - curr) <= cnt) {
          cnt -= (xr - b[curr - 1]) * (n - curr);
          curr--;
          xr = b[curr];
        } else {
          long long tmp = (n - curr);
          xr -= cnt / tmp;
          return xr - xl;
        }
      }
    }
  }
  return xr - xl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << F() << "\n";
  return 0;
}
