#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2e5 + 5;
const long long mod = 1e9 + 7;
int n;
long long k, a[MAXN], pre[MAXN];
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + 1 + n);
  long long l = 1, r = n, cntl = 1, cntr = 1;
  while (l < r) {
    if (cntl <= cntr) {
      if (cntl * (a[l + 1] - a[l]) <= k) {
        k -= cntl * (a[l + 1] - a[l]);
        cntl++;
        l++;
      } else {
        break;
      }
    } else {
      if (cntr * (a[r] - a[r - 1]) <= k) {
        k -= cntr * (a[r] - a[r - 1]);
        cntr++;
        r--;
      } else {
        break;
      }
    }
  }
  if (cntl <= cntr)
    a[l] += k / cntl;
  else
    a[r] -= k / cntr;
  printf("%lld\n", a[r] - a[l]);
  return 0;
}
