#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
void print(set<pair<long long, long long>>& s) {
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << it->first << " " << it->second << "\n";
  }
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<pair<long long, long long>> v;
  map<long long, long long> cnt;
  for (long long ele : a) cnt[ele]++;
  for (pair<long long, long long> p : cnt) {
    v.push_back(p);
  }
  sort(v.begin(), v.end());
  long long l = 0, r = v.size() - 1;
  while (k > 0 && l < r) {
    pair<long long, long long> left = v[l];
    pair<long long, long long> right = v[r];
    long long l_cnt = left.second;
    long long r_cnt = right.second;
    if (l_cnt > k && r_cnt > k) {
      break;
    }
    if (l_cnt <= r_cnt) {
      long long cur_val = left.first;
      long long next_val = v[l + 1].first;
      long long diff = next_val - cur_val;
      if (k >= l_cnt * diff) {
        k -= l_cnt * diff;
        v[l + 1].second += v[l].second;
      } else {
        long long possible = k / l_cnt;
        long long possible_next_val = cur_val + possible;
        long long ans = right.first - possible_next_val;
        cout << ans << "\n";
        return;
      }
      l++;
    } else {
      long long cur_val = right.first;
      long long next_val = v[r - 1].first;
      long long diff = cur_val - next_val;
      if (k >= r_cnt * diff) {
        k -= r_cnt * diff;
        v[r - 1].second += v[r].second;
      } else {
        long long possible = k / r_cnt;
        long long possible_next_val = cur_val - possible;
        long long ans = possible_next_val - left.first;
        cout << ans << "\n";
        return;
      }
      r--;
    }
  }
  long long ans = v[r].first - v[l].first;
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
