#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (1 << 20);
long long a[MAXN], n, k;
void read() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
}
void gen() {
  n = 1 + rand() % 100;
  k = 1 + rand() % 100;
  for (long long i = 0; i < n; i++) a[i] = 1 + rand() % 1000;
}
long long mean;
long long pref[MAXN], suf[MAXN];
bool check_pr(long long val) {
  long long ret = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] < val) ret += val - a[i];
  return ret <= k;
}
bool check_suf(long long val) {
  long long ret = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] > val) ret += a[i] - val;
  return ret <= k;
}
long long solve() {
  if (n == 1) return 0;
  long long sum = 0;
  for (long long i = 0; i < n; i++) sum += a[i];
  sort(a, a + n);
  suf[n] = 0;
  pref[0] = 0;
  for (long long i = 0; i < n; i++) pref[i] = (i ? pref[i - 1] : 0) + a[i];
  for (long long i = n - 1; i >= 0; i--) suf[i] = suf[i + 1] + a[i];
  long long low = 0, high = (long long)1e10 + 42, mid, ans;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check_pr(mid)) {
      ans = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  long long ans1;
  low = ans + (sum % n != 0);
  high = (long long)1e10 + 42;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check_suf(mid)) {
      ans1 = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  return ans1 - ans;
}
long long solve_stupid() {
  if (n == 1) return 0;
  multiset<long long> st;
  for (long long i = 0; i < n; i++) st.insert(a[i]);
  long long ops = 0, _k = k;
  while (k && ops < 1000042) {
    if (*st.begin() == *prev(st.end())) break;
    long long mx = *prev(st.end()), bef_max = *prev(prev(st.end()));
    long long to_do = min(k, mx - bef_max + 1);
    to_do = min(to_do, *next(st.begin()) - *st.begin() + 1);
    to_do = min(to_do, (*prev(st.end()) - *st.begin()) / 2);
    st.erase(prev(st.end()));
    st.insert(mx - to_do);
    long long mn = *st.begin();
    st.erase(st.begin());
    mn += to_do;
    st.insert(mn);
    k -= to_do;
    ++ops;
  }
  k = _k;
  return *prev(st.end()) - *st.begin();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  cout << solve() << '\n';
  return 0;
  srand(time(0));
  for (int i = 0; i < 100000; i++) {
    gen();
    if (solve() != solve_stupid()) {
      cout << n << " " << k << '\n';
      for (int i = 0; i < n; i++) cout << a[i] << " ";
      cout << "OUTPUT: " << solve() << '\n';
      cout << "ANSWER: " << solve_stupid() << '\n';
      cout << '\n';
      return 0;
    }
  }
  return 0;
}
