#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MAXN = (int)3e5 + 5;
long long n, k;
long long arr[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long mxi = n - 1, mni = 0;
  long long is = 0;
  long long frk = arr[n - 1] - arr[0];
  long long mncur = arr[0];
  long long mxcur = arr[n - 1];
  while (mni < n && arr[mni] == arr[0]) {
    mni++;
  }
  mni--;
  while (mxi >= 0 && arr[mxi] == arr[n - 1]) mxi--;
  mxi++;
  while (is < k && mxi > mni && mxcur > mncur) {
    if (n - mxi > mni + 1) {
      long long frk = arr[mni + 1] - arr[mni];
      long long art = min(k - is, frk * (mni + 1));
      if (k - is < mni + 1) break;
      if (art == k - is) {
        mncur = min(mncur + art / (mni + 1), mxcur);
        is += ((art / (mni + 1)) * (mni + 1));
      } else {
        is += frk * (mni + 1);
        mni++;
        mncur = arr[mni];
      }
    } else {
      long long frk = arr[mxi] - arr[mxi - 1];
      long long art = min(k - is, frk * (n - mxi));
      if (k - is < n - mxi) {
        break;
      }
      if (art == k - is) {
        mxcur = max(mncur, mxcur - art / (n - mxi));
        is += ((art / (n - mxi)) * (n - mxi));
      } else {
        is += frk * (n - mxi);
        mxi--;
        mxcur = arr[mxi];
      }
    }
  }
  cout << mxcur - mncur << '\n';
}
