#include <bits/stdc++.h>
using namespace std;
long long a[500005];
int main() {
  long long n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]), sum += a[i];
  sort(a, a + n);
  long long r = n - 1, l = 0, m1 = k, m2 = k, al, ar, c1 = 1, c2 = 1;
  int k1 = k, k2 = k;
  while (l < n - 1) {
    if (c1 * (a[l + 1] - a[l]) <= m1) {
      m1 -= c1 * (a[l + 1] - a[l]);
      c1++;
      l++;
    } else
      break;
  }
  al = a[l] + m1 / c1;
  while (r > 0) {
    if (c2 * (a[r] - a[r - 1]) <= m2) {
      m2 -= c2 * (a[r] - a[r - 1]);
      c2++;
      r--;
    } else
      break;
  }
  ar = a[r] - m2 / c2;
  if (al >= ar) {
    if (sum % n)
      printf("1\n");
    else
      printf("0\n");
  } else
    printf("%lld", ar - al);
}
