#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long arr[500005];
long long sum = 0;
bool valid1(long long x) {
  if (ceil(1.0 * sum / n) > x) return 0;
  long long h = 0;
  for (int i = n - 1; i >= 0; i--)
    if (arr[i] > x) h += arr[i] - x;
  return h <= k;
}
long long search1() {
  long long lo = 0, hi = 10000000010, mid;
  while (hi - lo > 1) {
    mid = (hi + lo) / 2;
    if (valid1(mid))
      hi = mid;
    else
      lo = mid;
  }
  return hi;
}
bool valid2(long long x) {
  if (sum / n < x) return 0;
  long long h = 0;
  for (int i = 0; i < n; i++)
    if (arr[i] < x) h += x - arr[i];
  return h <= k;
}
long long search2() {
  long long lo = 0, hi = 10000000010, mid;
  while (hi - lo > 1) {
    mid = (hi + lo) / 2;
    if (valid2(mid))
      lo = mid;
    else
      hi = mid;
  }
  return lo;
}
int main() {
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    sum += arr[i];
  }
  sort(arr, arr + n);
  cout << search1() - search2() << endl;
}
