#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long n, k, l, a[MAXN], t;
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  l = 1;
  long long sol = a[n] - a[1], r = n;
  while (l < r && k) {
    if (l < n + 1 - r)
      l++, t = min(a[l] - a[l - 1], k / (l - 1)), k -= t * (l - 1);
    else
      t = min(a[r] - a[r - 1], k / (n + 1 - r)), k -= t * (n + 1 - r), r--;
    sol -= t;
  }
  printf("%lld", sol);
}
