#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
long long a[N];
int main() {
  int n;
  long long k;
  scanf("%lld", &n);
  scanf("%lld", &k);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  long long left = 1, right = n;
  while (a[left] == a[left + 1]) left++;
  while (a[right] == a[right - 1]) right--;
  while (k && left < right) {
    long long ctl = left, ctr = (n - right + 1);
    if (ctl < ctr) {
      long long temp = ctl * (a[left + 1] - a[left]);
      if (k <= temp) {
        a[left] += k / ctl;
        break;
      }
      k -= temp;
      a[left] = a[left + 1];
    } else {
      long long temp = ctr * (a[right] - a[right - 1]);
      if (k <= temp) {
        a[right] -= k / ctr;
        break;
      }
      k -= temp;
      a[right] = a[right - 1];
    }
    while (a[left] == a[left + 1]) left++;
    while (a[right] == a[right - 1]) right--;
  }
  printf("%lld\n", a[right] - a[left]);
  return 0;
}
