#include <bits/stdc++.h>
long long a[500010], up[500010], down[500010];
int main() {
  long long n, i, r, sum = 0, mid1, mid2, k, m, ans2, ans1, rold;
  scanf("%I64d %I64d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
  }
  mid1 = sum / n;
  mid2 = mid1;
  if (sum % n != 0) mid2++;
  a[n] = mid1;
  n++;
  a[n] = mid2;
  n++;
  std::sort(a, a + n);
  down[n - 1] = 0;
  up[0] = 0;
  m = 1;
  r = 0;
  rold = 0;
  for (i = n - 2; i >= 0; i--) {
    r += (a[i + 1] - a[i]) * m;
    if (r > k) {
      long long c1 = a[i], c2 = a[i + 1], c3;
      while (c1 != c2) {
        c3 = (c1 + c2) / 2;
        r = (a[i + 1] - c3) * m + rold;
        if (r > k)
          c1 = c3 + 1;
        else
          c2 = c3;
      }
      ans2 = c1;
      break;
    }
    if (a[i] == mid2) {
      ans2 = mid2;
      break;
    }
    rold = r;
    m++;
  }
  r = 0;
  m = 1;
  rold = 0;
  for (i = 1; i < n; i++) {
    r += (a[i] - a[i - 1]) * m;
    if (r > k) {
      long long c1 = a[i - 1], c2 = a[i], c3;
      while (c1 != c2) {
        c3 = (c1 + c2 + 1) / 2;
        r = (c3 - a[i - 1]) * m + rold;
        if (r > k)
          c2 = c3 - 1;
        else
          c1 = c3;
      }
      ans1 = c1;
      break;
    }
    if (a[i] == mid1) {
      ans1 = mid1;
      break;
    }
    rold = r;
    m++;
  }
  printf("%I64d", ans2 - ans1);
  return 0;
}
