#include <bits/stdc++.h>
using namespace std;
long long n, k, a[600000], L, R, r, t, l, f;
long long s;
bool ok(long long x) {
  long long r = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] > x) r += (a[i] - x);
  if (r <= t) return 1;
  return 0;
}
bool ok1(long long x) {
  long long r = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] < x) r += (x - a[i]);
  if (r <= t) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> t;
  L = 2e9;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    L = min(L, a[i]);
    R = max(R, a[i]);
  }
  long long d1 = R, d2 = L;
  l = L;
  r = R;
  while (r - l > 10) {
    long long mid = (r + l) / 2;
    if (ok(mid))
      r = mid;
    else
      l = mid + 1;
  }
  for (long long i = l; i <= r; i++)
    if (ok(i)) d1 = min(d1, i);
  l = L;
  r = R;
  while (r - l > 10) {
    long long mid = (r + l) / 2;
    if (ok1(mid))
      l = mid;
    else
      r = mid - 1;
  }
  for (long long i = l; i <= r; i++)
    if (ok1(i)) d2 = max(d2, i);
  if (s % n == 0)
    f = 0;
  else
    f = 1;
  cout << max(f, d1 - d2);
}
