#include <bits/stdc++.h>
using namespace std;
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
long long arr[100010];
map<long long, long long> Map;
set<long long> Set;
set<long long>::iterator it;
set<long long>::reverse_iterator rit;
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    Map[arr[i]]++;
    Set.insert(arr[i]);
  }
  while (!Set.empty()) {
    it = Set.begin();
    long long Min = *it;
    rit = Set.rbegin();
    long long Max = *rit;
    if (Min == Max) break;
    long long Mincnt = Map[Min];
    long long Maxcnt = Map[Max];
    if (Mincnt < Maxcnt) {
      if (k < Mincnt) break;
      Set.erase(Min);
      it = Set.begin();
      long long nxtMin = *it;
      long long dif = nxtMin - Min;
      if (dif * Mincnt <= k) {
        k -= dif * Mincnt;
        Map[nxtMin] += Mincnt;
      } else if (k < dif * Mincnt) {
        long long koto = k / Mincnt;
        nxtMin = Min + koto;
        Set.insert(nxtMin);
        break;
      }
    } else {
      if (k < Maxcnt) break;
      Set.erase(Max);
      rit = Set.rbegin();
      long long nxtMax = *rit;
      long long dif = Max - nxtMax;
      if (dif * Maxcnt <= k) {
        k -= dif * Maxcnt;
        Map[nxtMax] += Maxcnt;
      } else if (k < dif * Maxcnt) {
        long long koto = k / Maxcnt;
        nxtMax = Max - koto;
        Set.insert(nxtMax);
        break;
      }
    }
  }
  it = Set.begin();
  long long FMin = *it;
  rit = Set.rbegin();
  long long FMax = *rit;
  long long res = FMax - FMin;
  printf("%lld", res);
  printf("\n");
}
