#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<long long> vect1;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    vect1.push_back(a);
  }
  sort(vect1.begin(), vect1.end(), greater<long long>());
  vector<pair<long long, long long> > vect;
  for (int i = 0; i < n; i++) {
    long long count1 = 1, val = vect1[i];
    while (i < n - 1 && vect1[i] == vect1[i + 1]) i++, count1++;
    vect.push_back(make_pair(val, count1));
  }
  long long i = 0, j = vect.size() - 1, flag = 0, flag2 = 0;
  while (i < j && k > 0) {
    if (vect[i].second <= vect[j].second && flag == 0) {
      if ((vect[i].first - vect[i + 1].first) * vect[i].second > k) {
        long long k2 = k;
        k -= (k / vect[i].second) * vect[i].second;
        vect[i].first -= k2 / vect[i].second;
        flag++;
      } else {
        k -= (vect[i].first - vect[i + 1].first) * vect[i].second;
        vect[i + 1].second += vect[i].second;
        i++;
      }
    } else {
      if ((vect[j - 1].first - vect[j].first) * vect[j].second > k) {
        long long k2 = k;
        k -= (k / vect[j].second) * vect[j].second;
        vect[j].first += k2 / vect[j].second;
        flag2++;
      } else {
        k -= (vect[j - 1].first - vect[j].first) * vect[j].second;
        vect[j - 1].second += vect[j].second;
        j--;
      }
    }
    if (flag == 1 && flag2 == 1 || flag2 > 1) break;
  }
  cout << vect[i].first - vect[j].first << endl;
  return 0;
}
