#include <bits/stdc++.h>
const long long maxn = 5e5 + 10;
long long a[maxn];
struct dup {
  long long am, cnt;
};
dup plat[maxn];
long long top = 0;
int main() {
  std::ios::sync_with_stdio(false);
  long long n, k;
  std::cin >> n >> k;
  for (long long i = 0; i < n; i++) std::cin >> a[i];
  std::sort(a, a + n);
  plat[top].am = a[0];
  plat[top].cnt = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1])
      plat[top].cnt++;
    else {
      ++top;
      plat[top].am = a[i];
      plat[top].cnt = 1;
    }
  }
  std::map<long long, long long> map;
  for (long long i = 0; i <= top; i++) map[plat[i].am] = plat[i].cnt;
  while (k > 0 && map.size() >= 2) {
    auto poor = map.begin();
    auto rich = (--map.end());
    if (rich->first - poor->first <= 1) {
      break;
    }
    if (false && map.size() == 2) {
      long long total = poor->first * poor->second + rich->first * rich->second;
      long long num = poor->second + rich->second;
      if (num == 0) {
        std::cout << "crash" << std::endl;
        return 0;
      }
      long long tar = total / num;
      long long cbig = total % num;
      long long csm = num - cbig;
      map.clear();
      if (cbig > 0) {
        map[tar + 1] = cbig;
      }
      map[tar] = csm;
      break;
    } else {
      auto npoor = std::next(poor);
      auto nrich = std::prev(rich);
      long long d1 = npoor->first - poor->first;
      long long d2 = rich->first - nrich->first;
      if (map.size() == 2) {
        long long total =
            poor->first * poor->second + rich->first * rich->second;
        long long num = poor->second + rich->second;
        if (num == 0) {
          std::cout << "crash" << std::endl;
        }
        long long tar = total / num;
        d1 = tar - poor->first;
        d2 = rich->first - tar;
      }
      long long fill1 = d1 * poor->second;
      long long fill2 = d2 * rich->second;
      long long minfill = std::min(fill1, fill2);
      minfill = std::min(minfill, k);
      long long nump = poor->second;
      long long numr = rich->second;
      if (nump * numr == 0) {
        std::cout << "wrong answer" << std::endl;
        return 0;
      }
      long long sub = minfill / numr;
      long long add = minfill / nump;
      long long ressub = minfill % numr;
      long long othersub = numr - ressub;
      long long resadd = minfill % nump;
      long long otheradd = nump - resadd;
      if (add > 0) {
        map[poor->first + add] += otheradd;
      } else {
        poor->second -= resadd;
      }
      if (resadd > 0) map[poor->first + add + 1] += resadd;
      if (sub > 0) {
        map[rich->first - sub] += othersub;
      } else {
        rich->second -= ressub;
      }
      if (ressub > 0) map[rich->first - sub - 1] += ressub;
      if (sub > 0) map.erase(--map.end());
      if (add > 0) map.erase(map.begin());
      k -= minfill;
    }
  }
  auto poor = map.begin();
  auto rich = --map.end();
  std::cout << rich->first - poor->first << std::endl;
  return 0;
}
