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