#include <bits/stdc++.h>
using namespace std;
const long long maxn = 500010;
long long n, k, c[maxn], sum, ans1, ans2, maxx;
bool check1(long long x) {
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    if (c[i] >= x) break;
    res += x - c[i];
  }
  if (res <= k) return true;
  return false;
}
bool check2(long long x) {
  long long res = 0;
  for (long long i = n; i >= 1; i--) {
    if (c[i] <= x) break;
    res += c[i] - x;
  }
  if (res <= k) return true;
  return false;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
    maxx = max(maxx, c[i]);
    sum += c[i];
  }
  sort(c + 1, c + 1 + n);
  long long l = 1, r = sum / n;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check1(mid)) {
      ans1 = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  if (sum % n == 0)
    l = sum / n;
  else
    l = sum / n + 1;
  r = maxx;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check2(mid)) {
      ans2 = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld\n", ans2 - ans1);
  return 0;
}
