#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 7;
const long long xinc[] = {0, 0, 1, -1};
const long long yinc[] = {1, -1, 0, 0};
const long double PI = acos(-1.0);
long long n, a[N], sum, ub, lb, mx, mn, k;
vector<long long> up, down;
long long dist1(long long x) {
  long long ret = 0;
  for (auto i : up) ret += max(i - x, 0LL);
  return ret;
}
long long dist2(long long x) {
  long long ret = 0;
  for (auto i : down) ret += max(x - i, 0LL);
  return ret;
}
long long find_up() {
  long long lo = ub, hi = mx;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (dist1(mid) <= k)
      hi = mid;
    else
      lo = mid;
  }
  if (dist1(lo) <= k)
    return lo;
  else if (dist1(hi) <= k)
    return hi;
  else
    assert(false);
}
long long find_lo() {
  long long lo = mn, hi = lb;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (dist2(mid) <= k)
      lo = mid;
    else
      hi = mid;
  }
  if (dist2(hi) <= k)
    return hi;
  else if (dist2(lo) <= k)
    return lo;
  else
    assert(false);
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mx = max(a[i], mx);
    mn = min(a[i], mn);
  }
  lb = sum / n;
  ub = (sum + n - 1) / n;
  for (long long i = 0; i < n; i++) {
    if (a[i] > ub)
      up.push_back(a[i]);
    else
      down.push_back(a[i]);
  }
  long long fupper = find_up();
  long long flower = find_lo();
  cout << fupper - flower << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
