#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int64_t> left(n), right(n);
  for (int i = 0; i < n; i++) {
    if (i == 0)
      left[i] = 0;
    else
      left[i] = left[i - 1] + i * (a[i] - a[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1)
      right[i] = 0;
    else
      right[i] = right[i + 1] + (n - 1 - i) * (a[i + 1] - a[i]);
  }
  int64_t start = 0, end = n - 1;
  int64_t ans = a[end] - a[start];
  while (1) {
    if (start >= end) break;
    int64_t minus = a[start + 1] - a[start] + a[end] - a[end - 1];
    if (start + 1 == end) minus = a[end] - a[start];
    if (minus > k / (start + 1)) minus = k / (start + 1);
    ans -= minus;
    k -= minus * (start + 1);
    start++;
    end--;
  }
  cout << ans << endl;
  return 0;
}
