#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const long long maxn = (long long)5e5 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max() - 1;
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
long long dxx[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dyy[] = {1, 0, -1, 0, 1, -1, 1, -1};
void solve() {
  long long n, k;
  cin >> n >> k;
  long long a[n + 5];
  for (int i = 1; i <= (n); i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  long long l = 1, r = n;
  long long L = 1, R = 1;
  long long mn = a[1], mx = a[n];
  bool ok = 0;
  while (l < r && k > 0) {
    bool op = 0;
    if (L <= R && !ok) {
      if ((a[l + 1] - a[l]) * L <= k)
        k -= (a[l + 1] - a[l]) * L, L++, op = 1, mn = a[l + 1], l++;
      else {
        long long p = k / L;
        if (p == 0)
          ok = 1;
        else {
          op = 1;
          k -= p * L;
          mn += p;
        }
      }
    } else if (R <= L) {
      if ((a[r] - a[r - 1]) * R <= k)
        k -= (a[r] - a[r - 1]) * R, R++, op = 1, mx = a[r - 1], r--;
      else {
        long long p = k / R;
        if (p != 0) {
          op = 1;
          k -= p * R;
          mx -= p;
        }
      }
    }
    if (!op) break;
  }
  cout << mx - mn << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
  long long CT = 0;
  while (T--) {
    solve();
  }
  return 0;
}
