#include <bits/stdc++.h>
using namespace std;
int a[500000];
int mina, maxa;
int n, k;
long long sum = 0;
bool check(int c) {
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] + c < mina) {
      sum += mina - c - a[i];
    } else {
      break;
    }
  }
  if (sum > k) return false;
  return true;
}
bool checkp(int c) {
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] - c > maxa) {
      sum += a[i] - c - maxa;
    }
  }
  if (sum > k) return false;
  return true;
}
int main() {
  scanf("%d %d", &n, &k);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  if (sum % n == 0) {
    mina = maxa = sum / n;
  } else {
    mina = sum / n;
    maxa = sum / n + 1;
  }
  sort(a, a + n);
  int ll = 0, rr = 1000000000;
  while (ll != rr) {
    int mid = (ll + rr) / 2;
    if (check(mid)) {
      rr = mid;
    } else {
      ll = mid + 1;
    }
  }
  int lll = 0, rrr = 1000000000;
  while (lll != rrr) {
    int mid = (lll + rrr) / 2;
    if (checkp(mid)) {
      rrr = mid;
    } else {
      lll = mid + 1;
    }
  }
  printf("%lld", (long long)lll + ll + maxa - mina);
  scanf("%d", &n);
  return 0;
}
