#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, j, l = 0, p = 0, q = 0, w, i = 0, flag = 0, k, t, r = 0, d;
  cin >> n >> k;
  long long a[n], b[n];
  map<long long, long long> m1;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    m1[a[i]]++;
  }
  sort(b, b + n);
  long long c = 1;
  l = n - 1;
  p = b[n - 1] - b[0];
  while (i < l && k) {
    if (i == l - 1) {
      d = min(b[i + 1] - b[i], k / c);
    } else {
      d = min(b[i + 1] - b[i] + b[l] - b[l - 1], k / c);
    }
    p -= d;
    k -= (d * c);
    l--;
    i++;
    c++;
  }
  cout << p;
  return 0;
}
