#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  long long first = 1, second = n, fc = 1, sc = 1;
  while (k) {
    while (a[first] == a[first + 1] && first <= second) fc++, first++;
    while (a[second] == a[second - 1] && first <= second) sc++, second--;
    if (fc >= sc) {
      if (sc * (a[second] - a[second - 1]) <= k) {
        k -= sc * (a[second] - a[second - 1]);
        second--, sc++;
      } else
        a[second] -= k / sc, k = 0;
    } else {
      if (fc * (-a[first] + a[first + 1]) <= k) {
        k -= fc * (-a[first] + a[first + 1]);
        first++, fc++;
      } else
        a[first] += k / fc, k = 0;
    }
  }
  if (first >= second)
    cout << 0;
  else
    cout << a[second] - a[first];
  return 0;
}
