#include <bits/stdc++.h>
using namespace std;
int n, k;
const int MAXN = 500000;
int A[MAXN + 10];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  A[n + 1] = INT_MAX;
  A[0] = INT_MIN;
  sort(A + 1, A + n + 1);
  int l = 1, r = n;
  for (l = 2; l <= n && A[l] == A[l - 1]; l++)
    ;
  l--;
  int days = k;
  while (l <= n) {
    long long d = l * (long long)(A[l + 1] - A[l]);
    if (d <= days) {
      days -= d;
      A[l] = A[l + 1];
      while (l <= n && A[l] == A[l + 1]) l++;
    } else {
      long long m = days / l, M = days % l, v = A[l] + m;
      for (int i = 1; i <= l; i++) A[i] = v;
      for (int i = 0; i < M; i++) A[l - i] = v + 1LL;
      break;
    }
  }
  for (r = n - 1; r > 0 && A[r] == A[r + 1]; r--)
    ;
  r++;
  days = k;
  while (r > 0) {
    long long d = (n - r + 1) * ((long long)A[r] - (long long)A[r - 1]);
    if (d <= days) {
      days -= d;
      A[r] = A[r - 1];
      while (r > 0 && A[r] == A[r - 1]) r--;
    } else {
      long long m = days / (n - r + 1), M = days % (n - r + 1), v = A[r] - m;
      for (int i = r; i <= n; i++) A[i] = v;
      for (int i = 0; i < M; i++) A[r + i] = v - 1LL;
      break;
    }
  }
  printf("%d\n", A[n] - A[1]);
  return 0;
}
