#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(30);
  long long n, k;
  cin >> n >> k;
  long long mx = 0, lol = 0, lol1 = 0, mn = 1e18;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    mx = max(mx, v[i]);
    mn = min(mn, v[i]);
  }
  for (auto to : v) {
    lol += mx - to;
    lol1 += to - mn;
  }
  sort(v.begin(), v.end());
  if (lol <= k || lol1 <= k) {
    cout << 0;
  } else {
    long long ind = 0, ind1 = v.size() - 1;
    while (true) {
      if (v[ind + 1] == v[ind]) {
        ind++;
        continue;
      }
      if (v[ind1] == v[ind1 - 1]) {
        ind1--;
        continue;
      }
      if ((ind + 1) <= (v.size() - ind1)) {
        long long dif = v[ind + 1] - v[ind];
        long long need = dif * (ind + 1);
        if (need < k) {
          k -= need;
          ind++;
        } else {
          v[ind] += k / (ind + 1);
          break;
        }
      } else {
        long long dif = v[ind1] - v[ind1 - 1];
        long long need = dif * (v.size() - ind1);
        if (need < k) {
          k -= need;
          ind1--;
        } else {
          v[ind1] -= k / (v.size() - ind1);
          break;
        }
      }
    }
    cout << max(0ll, v[ind1] - v[ind]);
  }
}
