#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
int n, k, C[N];
void solve() {
  sort(C + 1, C + n + 1);
  int reached = C[1], id = 1, temp = k;
  for (int i = 2, _b = (n); i <= _b; i++) {
    if ((C[i] - reached) * (long long)(i - 1) <= k) {
      k -= (C[i] - reached) * (i - 1);
      reached = C[i];
      id = i;
    } else
      break;
  }
  int add = k / id, rest = k % id;
  for (int i = 1, _b = (id); i <= _b; i++) C[i] = reached + add + (i <= rest);
  k = temp;
}
void rev() {
  for (int i = 1, _b = (n); i <= _b; i++) C[i] = -C[i];
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1, _b = (n); i <= _b; i++) scanf("%d", &C[i]);
  solve();
  rev();
  solve();
  rev();
  sort(C + 1, C + n + 1);
  printf("%d\n", C[n] - C[1]);
  return 0;
}
