#include <bits/stdc++.h>
using std::memset;
using std::pow;
using std::printf;
using std::scanf;
const double eps = 1e-9;
int n;
long long peo[500005];
int k;
long long all;
bool judgedown(long long mid) {
  long long tmp = 0;
  for (int i = 0; i < n; ++i) {
    tmp += std::max(mid - peo[i], 0LL);
  }
  return tmp <= k;
}
bool judgeup(long long mid) {
  long long tmp = 0;
  for (int i = 0; i < n; ++i) {
    tmp += std::max(peo[i] - mid, 0LL);
  }
  return tmp <= k;
}
long long binaryup() {
  long long left = all % n ? all / n : all / n - 1;
  long long right = peo[n - 1];
  while (left + 1 < right) {
    long long mid = (left + right) / 2;
    if (judgeup(mid)) {
      right = mid;
    } else {
      left = mid;
    }
  }
  return right;
}
long long binarydown() {
  long long left = peo[0];
  long long right = all / n + 1;
  while (left + 1 < right) {
    long long mid = (left + right) / 2;
    if (judgedown(mid)) {
      left = mid;
    } else {
      right = mid;
    }
  }
  return left;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", peo + i);
    all += peo[i];
  }
  std::sort(peo, peo + n);
  printf("%lld\n", binaryup() - binarydown());
}
