#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  map<ll, ll> freq;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    freq[x]++;
  }
  while ((int)freq.size() > 1) {
    auto small = freq.begin();
    auto big = freq.end();
    --big;
    if (k < min(small->second, big->second)) {
      break;
    }
    if (small->second <= big->second) {
      auto p = freq.begin();
      p++;
      ll cnt = small->second;
      ll move = min(k / cnt, p->first - small->first);
      freq[small->first + move] += cnt;
      k -= move * cnt;
      freq.erase(small->first);
    } else {
      auto p = freq.end();
      --p;
      --p;
      ll cnt = big->second;
      ll move = min(k / cnt, big->first - p->first);
      freq[big->first - move] += cnt;
      k -= move * cnt;
      freq.erase(big->first);
    }
  }
  int ans = freq.rbegin()->first - freq.begin()->first;
  cout << ans << endl;
}
