#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n;
long long k;
long long a[100005];
void enter() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
}
void solve() {
  int L = 1, R = n;
  while (k && L < R) {
    while (L < R && a[L] == a[L + 1]) L++;
    while (L < R && a[R] == a[R - 1]) R--;
    int u = min(L, n - R + 1);
    if (k < u) break;
    if (u == L) {
      long long x = min(a[L + 1] - a[L], k / u);
      a[L] += x;
      k -= 1ll * x * u;
    } else {
      long long x = min(a[R] - a[R - 1], k / u);
      a[R] -= x;
      k -= 1ll * x * u;
    }
  }
  cout << a[R] - a[L];
}
int main() { enter(), solve(); }
