#include <bits/stdc++.h>
using namespace std;
long long t, n, m, k, a[100010], p[100010];
deque<pair<long long, long long> > pr;
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  long long ac = a[1], cnt = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] != ac) {
      pr.push_back(make_pair(ac, cnt));
      ac = a[i];
      cnt = 1;
    } else {
      cnt++;
    }
  }
  pr.push_back(make_pair(ac, cnt));
  long long res = 10e9;
  while ((k > 0) && (pr.size()) > 1) {
    auto f = pr.front(), b = pr.back();
    if (f.second < b.second) {
      pr.pop_front();
      long long cnt = f.second;
      long long d = ((pr.front()).first) - f.first;
      d -= min(k / cnt, d);
      if (d == (((pr.front()).first) - f.first)) {
        pr.push_front(f);
        break;
      }
      k -= min(k / cnt, ((pr.front()).first) - f.first) * cnt;
      if (d == 0) {
        (pr.front()).second += cnt;
      } else {
        f.first += (((pr.front()).first) - f.first - d);
        pr.push_front(f);
      }
    } else {
      pr.pop_back();
      long long cnt = b.second;
      long long d = b.first - ((pr.back()).first);
      d -= min(k / cnt, d);
      if (d == (b.first - ((pr.back()).first))) {
        pr.push_back(b);
        break;
      }
      k -= min(k / cnt, b.first - ((pr.back()).first)) * cnt;
      if (d == 0) {
        (pr.back()).second += cnt;
      } else {
        b.first -= b.first - ((pr.back()).first) - d;
        pr.push_back(b);
      }
    }
  }
  cout << ((pr.back()).first - (pr.front()).first);
  return 0;
}
