#include <bits/stdc++.h>
using namespace std;
struct TT {
  int a, b, dir;
};
TT tt[1];
long long ff[500011], n, m, i, j, k, l, t, s, r, mmax, mmin, num, ans;
long long MOD = 1e9 + 7;
void solve() {
  sort(ff + 1, ff + n + 1);
  t = k;
  m = ff[1];
  for (i = 2; i <= n; i++) {
    r = (ff[i] - m) * (i - 1);
    if (r <= t)
      t -= r;
    else
      break;
    m = ff[i];
  }
  j = i - 1;
  r = t / j;
  s = t % j;
  for (i = 1; i <= j; i++) ff[i] = m + r + (i <= s);
  for (i = 1; i <= n; i++) ff[i] = -ff[i];
}
int main() {
  scanf("%I64d%I64d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%I64d", &ff[i]), num += ff[i];
  solve();
  solve();
  sort(ff + 1, ff + n + 1);
  ans = ff[n] - ff[1];
  printf("%I64d\n", ans);
  return 0;
}
