#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
const int INF = 0x3f3f3f3f;
long long n, k, a[MAXN];
long long sum;
long long check1(int m) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < m) sum = sum + (m - a[i]);
  }
  return sum;
}
long long check2(int m) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > m) sum = sum + (a[i] - m);
  }
  return sum;
}
int main() {
  while (~scanf("%lld%lld", &n, &k)) {
    sum = 0;
    long long MAX = -1, MIN = INF;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      MAX = max(MAX, a[i]);
      MIN = min(MIN, a[i]);
      sum += a[i];
    }
    long long poor = 0, rich = 0;
    long long l = MIN, r = sum / n, m = l + (r - l) / 2;
    while (l <= r) {
      if (check1(m) <= k) {
        poor = m;
        l = m + 1;
      } else if (check1(m) > k)
        r = m - 1;
      m = l + (r - l) / 2;
    }
    l = sum / n, r = MAX;
    if (sum % n) l++;
    m = l + (r - l) / 2;
    while (l <= r) {
      if (check2(m) <= k) {
        rich = m;
        r = m - 1;
      } else if (check2(m) > k)
        l = m + 1;
      m = l + (r - l) / 2;
    }
    printf("%lld\n", rich - poor);
  }
  return 0;
}
