#include <bits/stdc++.h>
using namespace std;
int n;
long long k, a[500005];
int chack1(int x) {
  long long k1 = 0, c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > x)
      k1 += (a[i] - x);
    else
      c += (x - a[i]);
  }
  if (k1 <= k && c >= k1)
    return 1;
  else
    return 0;
}
int chack2(int x) {
  long long k2 = 0, c1 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < x)
      k2 += (x - a[i]);
    else
      c1 += (a[i] - x);
  }
  if (k2 <= k && c1 >= k2)
    return 1;
  else
    return 0;
}
int main() {
  while (cin >> n >> k) {
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int max = a[n - 1], min = a[0];
    int low = min, high = max;
    while (low <= high) {
      int mid = (low + high) / 2;
      long long k1 = 0, c = 0;
      if (chack1(mid))
        high = mid - 1, max = mid;
      else
        low = mid + 1;
    }
    low = 0, high = a[n - 1];
    while (low <= high) {
      int mid = (low + high) / 2;
      if (chack2(mid))
        low = mid + 1, min = mid;
      else
        high = mid - 1;
    }
    cout << max - min << endl;
  }
  return 0;
}
