#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
long long k;
long long a[maxn];
long long b[maxn], c[maxn], d[maxn];
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i);
  sort(a + 1, a + n + 1);
  int m = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[m]) {
      ++b[m];
    } else {
      a[++m] = a[i];
      b[m] = 1;
    }
  }
  n = m;
  for (int i = 1; i <= n; i++) {
    c[i] = c[i - 1] + b[i];
  }
  for (int i = n; i; i--) {
    d[i] = d[i + 1] + b[i];
  }
  int l = 1, r = n;
  long long L = a[l], R = a[r];
  while (l != r) {
    if (c[l] <= d[r]) {
      if (c[l] * (a[l + 1] - a[l]) > k) {
        L = a[l] + k / c[l];
        break;
      } else {
        k -= c[l] * (a[l + 1] - a[l]);
        L = a[++l];
      }
    } else {
      if (d[r] * (a[r] - a[r - 1]) > k) {
        R = a[r] - k / d[r];
        break;
      } else {
        k -= d[r] * (a[r] - a[r - 1]);
        R = a[--r];
      }
    }
  }
  printf("%lld\n", R - L);
  return 0;
}
