#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 5e5 + 5;
int n, k, C[N];
void doit() {
  sort(C + 1, C + n + 1);
  int last = C[1], temp = k;
  for (int i = 2; i <= n; i++) {
    if ((C[i] - last) * (long long)(i - 1) <= k) {
      k -= (C[i] - last) * (i - 1);
      last = C[i];
    }
  }
  int j = 0;
  while (j + 1 <= n && C[j + 1] <= last) j++;
  int go = k / j, left = k % j;
  for (int i = 1; i <= j; i++) C[i] = last + go + (i <= left);
  k = temp;
}
void rev() {
  for (int i = 1; i <= n; i++) C[i] = -C[i];
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &C[i]);
  doit();
  rev();
  doit();
  rev();
  sort(C + 1, C + n + 1);
  printf("%d\n", C[n] - C[1]);
  return 0;
}
