#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long a[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  long long l = 1, r = n;
  sort(a + 1, a + n + 1);
  long long mx = a[n], mn = a[1];
  while (k) {
    if (mx == mn) break;
    if (l <= (n - r + 1)) {
      if (k < l) break;
      long long tmp = min(k / l, (a[l + 1] - mn));
      k -= tmp * l;
      mn += tmp;
      while (mn == a[l + 1]) ++l;
    } else {
      if (k < (n - r + 1)) break;
      long long tmp = min(k / (n - r + 1), (mx - a[r - 1]));
      k -= tmp * (n - r + 1);
      mx -= tmp;
      while (mx == a[r - 1]) --r;
    }
  }
  cout << mx - mn << '\n';
  return 0;
}
