#include <bits/stdc++.h>
using namespace std;
const double PI = acos(0) * 2;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
int n;
long long a[500100], s, mngheo, nngheo, ngheo, mgiau, ngiau, giau, k;
vector<pair<long long, long long> > v;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), s += a[i];
  sort(a + 1, a + 1 + n);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1] && i != 1) {
      v.push_back(make_pair(a[i - 1], cnt));
      cnt = 1;
    } else
      cnt++;
  }
  v.push_back(make_pair(a[n], cnt));
  nngheo = v[0].second;
  mngheo = v[0].first;
  long long Lk = k;
  for (int i = 1; i < ((int)(v).size()); i++) {
    ngheo += (v[i].first - v[i - 1].first) * nngheo;
    if (ngheo >= k) {
      ngheo -= (v[i].first - v[i - 1].first) * nngheo;
      k -= ngheo;
      mngheo = v[i - 1].first + k / nngheo;
      break;
    }
    nngheo += v[i].second;
    mngheo = v[i].first;
  }
  if (mngheo > s / n) mngheo = s / n;
  ngiau = v[((int)(v).size()) - 1].second;
  mgiau = v[((int)(v).size()) - 1].first;
  k = Lk;
  for (int i = ((int)(v).size()) - 2; i >= 0; i--) {
    giau += (v[i + 1].first - v[i].first) * ngiau;
    if (giau >= k) {
      giau -= (v[i + 1].first - v[i].first) * ngiau;
      k -= giau;
      mgiau = v[i + 1].first - k / ngiau;
      break;
    }
    ngiau += v[i].second;
    mgiau = v[i].first;
  }
  if (mgiau < (s + n - 1) / n) mgiau = (s + n - 1) / n;
  cout << mgiau - mngheo;
}
