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