#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxn = 500000 + 5;
int A[maxn];
int n, k;
long long tot, lb, ub;
bool check1(int x) {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] - x > 0) res += A[i] - x;
  }
  return res <= k;
}
bool check2(int x) {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] - x < 0) res += x - A[i];
  }
  return res <= k;
}
int get_max() {
  int l = ub - 1, r = inf;
  while (l < r - 1) {
    int m = (l + r) >> 1;
    if (check1(m)) {
      r = m;
    } else
      l = m;
  }
  return r;
}
int get_min() {
  int l = 0, r = lb + 1;
  while (l < r - 1) {
    int m = (l + r) >> 1;
    if (check2(m)) {
      l = m;
    } else
      r = m;
  }
  return l;
}
int main(void) {
  scanf("%d", &(n));
  scanf("%d", &(k));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(A[i]));
    tot += A[i];
  }
  lb = tot / n;
  ub = (tot + n - 1) / n;
  int mi = get_min(), ma = get_max();
  printf("%d\n", ma - mi);
  return 0;
}
