#include <bits/stdc++.h>
using namespace std;
const long long N = 500009;
long long n, K, a[N];
int main() {
  scanf("%lld%lld", &n, &K);
  long long k = K;
  for (long long i = 1; i <= (n); i++) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  long long r = n;
  while (r > 1 && (a[r] - a[r - 1]) * (n - r + 1) <= k) {
    k -= (a[r] - a[r - 1]) * (n - r + 1);
    r--;
  }
  for (long long i = (n); i >= (r); i--) a[i] = a[r] - k / (n - r + 1);
  k = k % (n - r + 1);
  for (long long i = (r); i <= (r + k - 1); i++) a[i]--;
  k = K;
  r = 1;
  while (r < n && (a[r + 1] - a[r]) * r <= k) {
    k -= (a[r + 1] - a[r]) * r;
    r++;
  }
  for (long long i = 1; i <= (r); i++) a[i] = a[r] + k / r;
  k = k % r;
  for (long long i = (r); i >= (r - k + 1); i--) a[i]++;
  printf("%lld\n", a[n] - a[1]);
  return 0;
}
