#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 0x7f7f7f7f;
const double pi = acos(-1);
const int maxn = 100 + 500000;
long long a[maxn];
int main() {
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      sum += a[i];
    }
    sort(a, a + n);
    int maxn = a[n - 1], minn = a[0], tp = k;
    for (int i = n - 1; i >= 0; i--)
      if (maxn > a[i]) {
        if ((n - 1 - i) * (maxn - a[i]) <= tp) {
          tp -= (n - 1 - i) * (maxn - a[i]);
          maxn = a[i];
        } else {
          maxn -= tp / (n - 1 - i);
          break;
        }
      }
    tp = k;
    minn = a[0];
    for (int i = 0; i < n; i++)
      if (minn < a[i]) {
        if (i * (a[i] - minn) <= tp) {
          tp -= i * (a[i] - minn);
          minn = a[i];
        } else {
          minn += tp / i;
          break;
        }
      }
    if (minn >= maxn)
      printf("%d\n", sum % n == 0 ? 0 : 1);
    else
      printf("%d\n", maxn - minn);
  }
  return 0;
}
