#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
map<long long, long long> M;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  for (int i = (0); i < (n); i++) {
    int a;
    cin >> a;
    M[a]++;
  }
  while (1) {
    if ((int)M.size() == 1) break;
    auto mn = M.begin();
    auto mx = M.end();
    mx--;
    if (mn->second < mx->second) {
      auto it = M.begin();
      it++;
      long long cnt = 0;
      if ((it->first - mn->first) * mn->second > k) {
        cnt = k / mn->second;
      } else {
        cnt = it->first - mn->first;
      }
      if (cnt == 0) break;
      long long newK = mn->first + cnt;
      long long newVal = mn->second;
      M.erase(mn);
      M[newK] += newVal;
      k -= cnt * newVal;
    } else {
      auto it = mx;
      it--;
      long long cnt = 0;
      if ((mx->first - it->first) * mx->second > k) {
        cnt = k / mx->second;
      } else {
        cnt = (mx->first - it->first);
      }
      if (cnt == 0) break;
      long long newK = mx->first - cnt;
      long long newVal = mx->second;
      M.erase(mx);
      M[newK] += newVal;
      k -= cnt * newVal;
    }
  }
  auto mn = M.begin();
  auto mx = M.end();
  mx--;
  cout << mx->first - mn->first << endl;
  return 0;
}
