#include <bits/stdc++.h>
using namespace std;
const long long maxn = (long long)2e5 + 100;
const long long mod = (long long)1e9 + 7;
int n, a[maxn];
map<int, int> cnt;
long long k;
int main() {
  scanf("%d%lld", &n, &k);
  for (long long i = (1); i <= (n); ++i) scanf("%d", &a[i]), cnt[a[i]]++;
  sort(a + 1, a + 1 + n);
  int sz = unique(a + 1, a + 1 + n) - a - 1;
  int pos1 = 1, pos2 = sz, mn = a[pos1], mx = a[pos2], cnt1 = cnt[a[1]],
      cnt2 = cnt[a[sz]];
  while (1) {
    if (k == 0 || mn >= mx) break;
    if (cnt1 < cnt2) {
      long long sub = 0;
      if (a[pos1] == mn) {
        if (pos1 + 1 > sz) break;
        sub = a[pos1 + 1] - mn;
      } else
        sub = a[pos1] - mn;
      long long num = k / cnt1;
      if (num <= sub) {
        k = 0;
        mn += num;
        break;
      } else {
        k -= 1ll * cnt1 * sub;
        mn = a[++pos1];
        cnt1 += cnt[a[pos1]];
      }
    } else {
      long long sub = 0;
      if (a[pos2] == mx) {
        if (pos2 - 1 < 1) break;
        sub = mx - a[pos2 - 1];
      } else
        sub = mx - a[pos2];
      long long num = k / cnt2;
      if (num <= sub) {
        k = 0;
        mx -= num;
        break;
      } else {
        k -= 1ll * cnt2 * sub;
        mx = a[--pos2];
        cnt2 += cnt[a[pos2]];
      }
    }
  }
  if (k == 0)
    return printf("%d\n", mx - mn), 0;
  else
    puts("0");
}
