#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000 + 5;
int c[MAXN], n, k;
bool checkrich(long long int x) {
  long long int need = 0;
  for (int i = 1; i <= n; i++) {
    need += max(1LL * 0, 1LL * (c[i] - x));
  }
  if (need <= k) {
    return true;
  }
  return false;
}
bool checkpoor(long long int x) {
  long long int need = 0;
  for (int i = 1; i <= n; i++) {
    need += max(1LL * 0, 1LL * (x - c[i]));
  }
  if (need <= k) {
    return true;
  }
  return false;
}
int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    int minc = 0x3f3f3f3f, maxc = -1;
    long long int sum = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &c[i]);
      sum += c[i];
      minc = min(minc, c[i]);
      maxc = max(maxc, c[i]);
    }
    int richest, poorest;
    long long int l = (sum + n - 1) / n, r = 0x3f3f3f3f, mid;
    while (r >= l) {
      mid = (l + r) / 2;
      if (checkrich(mid)) {
        richest = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    l = 0, r = sum / n;
    while (r >= l) {
      mid = (l + r) / 2;
      if (checkpoor(mid)) {
        poorest = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    printf("%d\n", richest - poorest);
  }
  return 0;
}
