#include <bits/stdc++.h>
using namespace std;
int n;
long long int k;
vector<long long int> v;
vector<long long int> sum;
vector<long long int> tmp_sum;
long long int cnt(long long int L) {
  int id = upper_bound(v.begin(), v.end(), L) - v.begin();
  int cnt = id;
  long long int S = (long long int)(cnt)*L;
  id--;
  if (id >= 0) {
    S -= tmp_sum[id];
  }
  return S;
}
long long int cnt2(long long int L) {
  int id = upper_bound(v.begin(), v.end(), L) - v.begin();
  if (id == v.size()) return 0;
  long long int S = (long long int)(v.size() - id) * L;
  S = sum[id] - S;
  return S;
}
long long int f(long long int mid) { return abs(cnt2(mid) - cnt(mid)); }
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    long long int a;
    scanf("%lld", &a);
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  long long int mint = v[0];
  long long int maxt = v.back();
  if (mint == maxt) {
    puts("0");
    return 0;
  }
  sum = v;
  for (int i = 1; i < sum.size(); i++) {
    sum[i] += sum[i - 1];
  }
  tmp_sum = sum;
  while (mint + 1LL < maxt) {
    long long mid = (mint + maxt) >> 1LL;
    if (cnt(mid) > k) {
      maxt = mid;
    } else {
      mint = mid;
    }
  }
  long long int __LEF = mint;
  if (cnt(maxt) <= k) {
    __LEF = maxt;
  }
  for (int i = 0; i < v.size(); i++) {
    sum[i] = 0;
  }
  for (int i = v.size() - 1; i >= 0; i--) {
    sum[i] = v[i];
    if (i + 1 < sum.size()) {
      sum[i] += sum[i + 1];
    }
  }
  mint = v[0];
  maxt = v.back();
  while (mint + 1LL < maxt) {
    long long int mid = (mint + maxt) >> 1LL;
    if (cnt2(mid) > k) {
      mint = mid;
    } else {
      maxt = mid;
    }
  }
  long long int __RIG = maxt;
  if (cnt2(mint) <= k) {
    __RIG = mint;
  }
  if (__LEF < __RIG) {
    printf("%lld\n", __RIG - __LEF);
    return 0;
  }
  if (v.size() % 2) {
    long long int mid = v[(v.size()) / 2];
    int idd = -1;
    for (int i = 0; i < v.size(); i++) {
      if (v[i] != mid) {
        idd = i;
        break;
      }
    }
    int iddd = v.size();
    for (int i = v.size() - 1; i >= 0; i--) {
      if (v[i] != mid) {
        iddd = i;
        break;
      }
    }
    if (idd + 1 == v.size() - iddd) {
      if (cnt(mid - 1) == cnt2(mid + 1)) {
        puts("0");
        return 0;
      }
    }
    puts("1");
    return 0;
  } else {
    long long int mint = 0;
    long long int maxt = v.back();
    while (mint + 2LL < maxt) {
      long long int mid = (maxt - mint) / 3LL + mint;
      long long int mid2 = 2LL * (maxt - mint) / 3LL + mint;
      if (f(mid) < f(mid2)) {
        maxt = mid2;
      } else {
        mint = mid;
      }
    }
    long long int MM = LLONG_MAX;
    while (mint <= maxt) {
      MM = min(MM, f(mint));
      mint++;
    }
    if (MM == 0LL) {
      puts("0");
    } else {
      puts("1");
    }
  }
  return 0;
}
