#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 20, M = 1e7, mod = 1e9 + 7, inf = 1e9 + 7;
int a[N], n, k;
int check1(int mx) {
  long long kk = 0, buji = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > mx)
      kk += (a[i] - mx);
    else {
      buji += (mx - a[i]);
    }
  }
  if (kk <= k && buji >= kk)
    return 1;
  else
    return 0;
}
int check2(int mi) {
  long long kk = 0, buji = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] < mi)
      kk += (mi - a[i]);
    else
      buji += (a[i] - mi);
  }
  if (kk <= k && buji >= kk)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int mx = a[n], mi = a[1];
  int r = a[n], l = a[1];
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check1(mid))
      r = mid - 1, mx = mid;
    else
      l = mid + 1;
  }
  r = a[n], l = a[1];
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check2(mid))
      l = mid + 1, mi = mid;
    else
      r = mid - 1;
  }
  cout << mx - mi << endl;
  return 0;
}
