#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long n, k, a[maxn], st, en, c[2] = {1, 1};
int check() {
  int i;
  for (i = st; i < n; ++i) {
    if (a[i] == a[i + 1])
      c[0]++;
    else
      break;
  }
  for (i = en; i > 1; --i) {
    if (a[i] == a[i - 1])
      c[1]++;
    else
      break;
  }
  st = c[0];
  en = i;
  if (c[0] <= c[1]) return 1;
  return 0;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  st = 1, en = n;
  while (1) {
    if (a[st] == a[en]) break;
    int ans = check();
    if (ans == 1) {
      if ((a[st + 1] - a[st]) * c[0] <= k) {
        k = k - (a[st + 1] - a[st]) * c[0];
        a[1] = a[st + 1];
        a[st] = a[1];
      } else {
        int u = k / c[0];
        k -= u * c[0];
        a[1] += u;
        a[st] = a[1];
        break;
      }
    } else {
      if ((a[en] - a[en - 1]) * c[1] <= k) {
        k = k - (a[en] - a[en - 1]) * c[1];
        a[n] = a[en - 1];
        a[en] = a[n];
      } else {
        int u = k / c[1];
        k -= u * c[1];
        a[n] -= u;
        a[en] = a[n];
        break;
      }
    }
  }
  cout << a[n] - a[1];
  return 0;
}
