#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, k, sz, v;
  cin >> n >> k;
  vector<long long> data(n);
  for (auto &x : data) cin >> x;
  sort(data.begin(), data.end());
  deque<pair<long long, int>> q;
  q.push_back({data[0], 0});
  for (auto &x : data) {
    if (x == q.back().first)
      ++q.back().second;
    else
      q.push_back({x, 1});
  }
  while (q.size() > 1 && k > 0) {
    sz = (int)q.size() - 1;
    t = (q[1].first - q[0].first) * q[0].second;
    v = (q[sz].first - q[sz - 1].first) * q[sz].second;
    if (q[0].second < q[sz].second) {
      if (t <= k) {
        k -= t;
        q[1].second += q[0].second;
        q.pop_front();
      } else {
        t = k / q[0].second;
        q[0].first += t;
        k -= t * q[0].second;
        break;
      }
    } else {
      if (v <= k) {
        k -= v;
        q[sz - 1].second += q[sz].second;
        q.pop_back();
      } else {
        t = k / q.back().second;
        q.back().first -= t;
        k -= t * q.back().second;
        ;
        break;
      }
    }
  }
  t = k / q[0].second;
  q[0].first += t;
  k -= t * q[0].second;
  t = k / q.back().second;
  q.back().first -= t;
  cout << q.back().first - q[0].first << "\n";
  return 0;
}
