#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
long long a[maxn], n, k;
int check(long long x) {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < x) res += x - a[i];
  }
  return res <= k;
}
int check2(long long x) {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > x) res += a[i] - x;
  }
  return res <= k;
}
int main() {
  scanf("%lld%lld", &n, &k);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  long long limit = sum / n;
  long long limit2 = limit;
  if (sum % n) limit2++;
  long long ansx = 0, ansy = 0;
  long long l = 1, r = limit, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      ansx = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = limit2;
  r = sum;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check2(mid)) {
      ansy = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld\n", ansy - ansx);
  return 0;
}
