#include <bits/stdc++.h>
using namespace std;
long long a[200001];
int main() {
  map<long long, int> ma;
  vector<int> v;
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ma[a[i]]++;
  }
  sort(a + 1, a + n + 1);
  int m = unique(a + 1, a + n + 1) - a - 1;
  if (m == 1) {
    cout << 0 << endl;
    return 0;
  }
  int l = 1, r = m;
  bool flag = 1;
  long long ansa = a[l];
  long long ansi = a[r];
  while (r >= l && flag) {
    flag = 0;
    long long minn = (a[l + 1] - a[l]) * ma[a[l]];
    long long maxx = (a[r] - a[r - 1]) * ma[a[r]];
    if (ma[a[l]] < ma[a[r]]) {
      if (minn <= k) {
        if (k >= minn) k -= minn;
        ma[a[l + 1]] += ma[a[l]];
        l++;
        ansa = a[l];
        flag = 1;
      } else {
        long long t = k / ma[a[l]];
        ansa = a[l] + t;
        break;
      }
    } else {
      if (maxx <= k) {
        if (k >= maxx) k -= maxx;
        ma[a[r - 1]] += ma[a[r]];
        r--;
        ansi = a[r];
        flag = 1;
      } else {
        int t = k / ma[a[r]];
        ansi = a[r] - t;
        break;
      }
    }
  }
  cout << max(ansi - ansa, 0ll) << endl;
}
