#include <bits/stdc++.h>
using namespace std;
int n;
long long m, a[100050];
int main() {
  scanf("%d%lld", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
  sort(a + 1, a + n + 1);
  int l = 1, r = n;
  while (l < n && a[l] == a[l + 1]) ++l;
  while (r > l && a[r] == a[r - 1]) --r;
  while (l < r) {
    if (l > m && n - r + 1 > m) break;
    if (l < n - r + 1) {
      long long mn = min(a[l + 1] - a[l], m / l);
      m -= mn * l;
      a[l] += mn;
      while (l < r && a[l] == a[l + 1]) ++l;
    } else {
      long long mn = min(a[r] - a[r - 1], m / (n - r + 1));
      m -= mn * (n - r + 1);
      a[r] -= mn;
      while (l < r && a[r] == a[r - 1]) --r;
    }
  }
  printf("%lld\n", a[r] - a[l]);
  return 0;
}
