#include <bits/stdc++.h>
using namespace std;
int n;
long long K;
long long a[500500];
long long sum[500500];
long long up(long long K) {
  long long pass = 1e9;
  long long fail = 0;
  while (pass - fail > 1) {
    long long mid = (pass + fail) / 2;
    int k = lower_bound(a, a + n, mid) - a;
    long long over = sum[n] - sum[k] - (n - k) * mid;
    if (over < K)
      pass = mid;
    else
      fail = mid;
  }
  return pass;
}
long long down(long long K) {
  long long pass = 0;
  long long fail = 1e9;
  while (fail - pass > 1) {
    long long mid = (pass + fail) / 2;
    int k = upper_bound(a, a + n, mid) - a;
    long long less = k * mid - sum[k];
    if (less < K)
      pass = mid;
    else
      fail = mid;
  }
  return pass;
}
long long search(long long K) {
  if (up(K) - down(K) >= 2) return K;
  long long pass = 0;
  long long fail = K + 1;
  while (fail - pass > 1) {
    long long mid = (pass + fail) / 2;
    if (up(mid) - down(mid) >= 2)
      pass = mid;
    else
      fail = mid;
  }
  return pass;
}
int main() {
  cin >> n >> K;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a, a + n);
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
  long long num = search(K);
  long long u = up(num);
  long long d = down(num);
  long long useU = 0, useD = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= u) {
      useU += a[i] - u;
      a[i] = u;
    }
    if (a[i] <= d) {
      useD += d - a[i];
      a[i] = d;
    }
  }
  multiset<long long> st(a, a + n);
  while (useU < useD) {
    auto it = prev(st.end());
    long long mx = *it;
    useU++;
    if (mx - 1 >= *st.begin()) {
      st.erase(it);
      st.insert(mx - 1);
    } else
      break;
  }
  while (useU > useD) {
    auto it = st.begin();
    long long mn = *it;
    useD++;
    if (*st.rbegin() >= mn + 1) {
      st.erase(it);
      st.insert(mn + 1);
    } else
      break;
  }
  for (; useU < K; useU++) {
    auto itmin = st.begin();
    auto itmax = prev(st.end());
    long long mn = *itmin;
    long long mx = *itmax;
    if (mx - 1 >= mn + 1) {
      st.erase(itmin);
      st.erase(itmax);
      st.insert(mx - 1);
      st.insert(mn + 1);
    } else
      break;
  }
  long long ans = *st.rbegin() - *st.begin();
  cout << ans << endl;
}
