#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
long long a[N], k;
long long lp, ln, rp, rn;
void left(long long lop) {
  if (lop <= k) {
    k -= lop;
    lp++;
    ln++;
  } else {
    a[lp] = a[lp] + k / ln;
    k = k % ln;
  }
}
void right(long long rop) {
  if (rop <= k) {
    k -= rop;
    rp--;
    rn++;
  } else {
    a[rp] = a[rp] - k / rn;
    k = k % rn;
  }
}
int main() {
  scanf("%d%I64d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  sort(a, a + n);
  lp = 0, ln = 1;
  rp = n - 1, rn = 1;
  while (lp + 1 < n && a[lp] == a[lp + 1]) lp++, ln++;
  while (rp - 1 >= 0 && a[rp] == a[rp - 1]) rp--, rn++;
  while (lp < rp && k > 0) {
    long long lop = (a[lp + 1] - a[lp]) * ln;
    long long rop = (a[rp] - a[rp - 1]) * rn;
    if (ln < rn) {
      left(lop);
    } else if (ln > rn) {
      right(rop);
    } else if (ln == rn) {
      if (a[lp + 1] - a[lp] <= a[rp] - a[rp - 1]) {
        right(rop);
      } else
        left(lop);
    }
    if (k < ln && k < rn) break;
  }
  printf("%I64d\n", a[rp] - a[lp]);
}
