#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1000000000000;
const double eps = (double)1e-8;
const int mod = (int)1000000007;
const int maxn = (int)5 * 1e5 + 5;
long long n, k, a[maxn], mx, mn, kl0, kl1, kr0, kr1, l, r, mns, sz, nl, nr;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  sort(a + 1, a + n + 1);
  kl0 = 1;
  kl1 = 0;
  kr0 = 1;
  kr1 = 0;
  l = 1;
  r = n;
  while (l < r) {
    if (l == r - 1) {
      sz = (a[l] * kl0 + (a[l] - (long long)1) * kl1 + a[r] * kr0 +
            (a[r] + (long long)1) * kr1) /
           n;
      mns = 0;
      if (k < kl1)
        mn = a[l] - (long long)1;
      else {
        mns = kl1;
        kl0 += kl1;
        mn = min(a[l] + (k - mns) / kl0, sz);
      }
      if (k < kr1)
        mx = a[r] + (long long)1;
      else {
        mns = kr1;
        kr0 += kr1;
        mx = max(a[r] - (k - mns) / kr0,
                 sz + ((a[l] * kl0 + (a[l] - (long long)1) * kl1 + a[r] * kr0 +
                        (a[r] + (long long)1) * kr1) %
                           n >
                       0));
      }
      cout << mx - mn << "\n";
      break;
    }
    nl = kl0 * (a[l + 1] - a[l]) + kl1 * (a[l + 1] - a[l] + (long long)1);
    nr = kr0 * (a[r] - a[r - 1]) + kr1 * (a[r] - a[r - 1] + (long long)1);
    if (k < nl && k < nr) {
      if (k < kl1)
        mn = a[l] - (long long)1;
      else {
        mns = kl1;
        kl0 += kl1;
        mn = a[l] + (k - mns) / kl0;
      }
      if (k < kr1)
        mx = a[r] + (long long)1;
      else {
        mns = kr1;
        kr0 += kr1;
        mx = a[r] - (k - mns) / kr0;
      }
      cout << mx - mn << "\n";
      break;
    }
    if (nl == nr) {
      kl0 = kl1 + kl0 + 1;
      kr0 = kr1 + kr0 + 1;
      kl1 = 0;
      kr1 = 0;
      l++;
      r--;
      k -= nl;
      continue;
    }
    if (nl < nr) {
      kl0 = kl1 + kl0 + 1;
      kl1 = 0;
      l++;
      k -= nl;
      if (nl < kr1) {
        kr1 -= nl;
        kr0 += nl;
      } else {
        nl -= kr1;
        kr0 += kr1;
        kr1 = 0;
        a[r] -= nl / kr0 + (nl % kr0 > 0);
        if (nl % kr0 > 0) {
          kr1 = kr0 - nl % kr0;
          kr0 = nl % kr0;
        }
      }
      continue;
    }
    if (nl > nr) {
      kr0 = kr1 + kr0 + 1;
      kr1 = 0;
      r--;
      k -= nr;
      if (nr < kl1) {
        kl1 -= nr;
        kl0 += nr;
      } else {
        nr -= kl1;
        kl0 += kl1;
        kl1 = 0;
        a[l] += nr / kl0 + (nr % kl0 > 0);
        if (nr % kl0 > 0) {
          kl1 = kl0 - nr % kl0;
          kl0 = nr % kl0;
        }
      }
      continue;
    }
  }
  if (l == r) {
    cout << 0 << "\n";
  }
  return 0;
}
