#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  vector<int> A(n);
  for (int& a : A) scanf("%d", &a);
  sort(A.begin(), A.end());
  long long i = 0, j = n - 1, cost, difference = A[n - 1] - A[0];
  while (i < j) {
    cost = (i + 1) * (A[i + 1] - A[i]);
    if (cost > k) {
      difference -= k / (i + 1);
      break;
    } else {
      k -= cost;
      difference -= A[i + 1] - A[i];
    }
    ++i;
    if (i == j) break;
    cost = (n - j) * (A[j] - A[j - 1]);
    if (cost > k) {
      difference -= k / (n - j);
      break;
    } else {
      k -= cost;
      difference -= A[j] - A[j - 1];
    }
    --j;
  }
  printf("%lld\n", difference);
}
