#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  while (scanf("%d %d", &n, &k) == 2) {
    vector<long long> arr(n);
    long long tot = 0;
    multiset<long long> haha;
    set<long long> s;
    map<long long, int> banyak;
    for (int i = 0; i < n; i++) {
      scanf("%I64d", &arr[i]);
      tot += arr[i];
      banyak[arr[i]]++;
      s.insert(arr[i]);
    }
    sort(arr.begin(), arr.end());
    long long median = tot / n;
    for (int i = 0; i < n - (tot % n); i++) {
      haha.insert(median);
    }
    for (int i = 0; i < tot % n; i++) {
      haha.insert(median + 1);
    }
    long long kk = 0;
    multiset<long long>::iterator it = haha.begin();
    for (int i = 0; i < n; i++) {
      kk += abs(arr[i] - *it);
      it++;
    }
    kk /= 2;
    if (s.size() == 1) {
      if (banyak[*s.begin()] == 1) {
        printf("%I64d\n", *s.begin());
      } else {
        printf("0\n");
      }
      continue;
    }
    if (k > kk) {
      it = haha.begin();
      multiset<long long>::iterator it1 = haha.end();
      --it1;
      printf("%I64d\n", *it1 - *it);
    } else {
      long long a, b;
      long long kk = k;
      long long hehe = 0;
      for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
        set<long long>::iterator it1 = s.end();
        --it1;
        if (it == it1) break;
        hehe += banyak[*it];
        it1 = it;
        ++it1;
        long long temp = (*it1 - *it) * hehe;
        if (temp >= kk) {
          long long hoho = *it * hehe;
          hoho += kk;
          a = hoho / hehe;
          break;
        }
        kk -= temp;
      }
      hehe = 0;
      kk = k;
      set<long long>::iterator it = s.end();
      --it;
      for (; it != s.begin(); it--) {
        hehe += banyak[*it];
        set<long long>::iterator it1 = it;
        --it1;
        long long temp = (*it - *it1) * hehe;
        if (temp >= kk) {
          long long hoho = *it * hehe;
          hoho -= kk;
          if (hoho % hehe != 0)
            b = hoho / hehe + 1;
          else
            b = hoho / hehe;
          break;
        }
        kk -= temp;
      }
      printf("%I64d\n", b - a);
    }
  }
  return 0;
}
