#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
long long a[N];
long long n, k;
int main() {
  scanf("%I64d%I64d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%I64d", a + i);
  long long sum = 0;
  sort(a, a + n);
  for (int i = 0; i < n; i++) sum += a[i];
  long long ave = sum / n;
  long long t = 0, p = 0;
  for (int i = 0; i < n; i++)
    if (a[i] > ave) {
      t += a[i] - ave;
      p++;
    }
  if (p > sum - n * ave)
    t -= sum - n * ave;
  else
    t -= p;
  if (k >= t) {
    if (sum % n == 0)
      cout << 0 << endl;
    else
      cout << 1 << endl;
    return 0;
  }
  long long tot = k;
  long long up, down;
  for (long long i = n - 1; i > 0; i--) {
    if ((a[i] - a[i - 1]) * (n - i) < tot)
      tot -= (a[i] - a[i - 1]) * (n - i);
    else {
      up = a[i] - tot / (n - i);
      break;
    }
  }
  tot = k;
  for (long long i = 0; i < n - 1; i++) {
    if ((a[i + 1] - a[i]) * (i + 1) < tot)
      tot -= (a[i + 1] - a[i]) * (i + 1);
    else {
      down = a[i] + tot / (i + 1);
      break;
    }
  }
  cout << up - down << endl;
  return 0;
}
