#include <bits/stdc++.h>
const int N(5 * 1e5 + 10);
long long n, k, a[N], l, rht, r, let, sum, mid, maxn, ans1, ans2;
bool check1(long long mid) {
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < mid)
      cnt += mid - a[i];
    else
      break;
  }
  return cnt > k;
}
bool check2(long long mid) {
  long long cnt = 0;
  for (int i(n); i > 0; --i) {
    if (a[i] > mid)
      cnt += a[i] - mid;
    else
      break;
  }
  return cnt > k;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  std::sort(a + 1, a + 1 + n);
  l = a[1];
  r = sum / n;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (check1(mid))
      r = mid - 1;
    else {
      l = mid + 1;
      ans1 = mid;
    }
  }
  l = sum / n + static_cast<bool>(sum % n);
  r = a[n];
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (check2(mid))
      l = mid + 1;
    else {
      r = mid - 1;
      ans2 = mid;
    }
  }
  printf("%lld", ans2 - ans1);
  return 0;
}
