#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6e5;
const int INF = 2100000000;
struct dingxiao {
  int adj;
  int val;
  friend bool operator<(dingxiao a, dingxiao b) { return a.val > b.val; }
};
struct dingda {
  int adj;
  int val;
  friend bool operator<(dingda a, dingda b) { return a.val < b.val; }
};
priority_queue<dingxiao> Qdingxiao;
priority_queue<dingda> Qdingda;
int n, k;
int c[MAXN];
void input(int &r) {
  r = 0;
  char t = getchar();
  while (!isdigit(t)) t = getchar();
  int sign = 1;
  if (t == '-') sign = -1;
  while (!isdigit(t)) t = getchar();
  while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
  r = r * sign;
}
int main() {
  input(n);
  input(k);
  long long sum = 0;
  for (int i = 1; i <= n; i++) input(c[i]), sum += c[i];
  sort(c + 1, c + 1 + n);
  long long average = sum / n;
  long long l = 0, r = average;
  long long minmax;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long kk = 0;
    for (int i = 1; i <= n; i++)
      if (c[i] < mid) kk += mid - c[i];
    if (kk <= k)
      minmax = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  l = (sum + n - 1) / n, r = INF;
  long long maxmin;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long kk = 0;
    for (int i = 1; i <= n; i++)
      if (mid < c[i]) kk += c[i] - mid;
    if (kk <= k)
      maxmin = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%I64d\n", maxmin - minmax);
  return 0;
}
