#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
  int n;
  long long k;
  scanf("%d", &n), scanf("%lld", &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  pair<int, int> l = make_pair(0, 0), r = make_pair(0, 0);
  int curl, curr;
  for (int i = 2; i <= n; i++)
    if (a[i] != a[i - 1]) {
      l = make_pair(a[i - 1], i - 1), curl = i;
      break;
    }
  if (l.second == 0) {
    printf("0");
    return 0;
  }
  for (int i = n - 1; i >= 1; i--)
    if (a[i] != a[i + 1]) {
      r = make_pair(a[i + 1], n - i), curr = i;
      break;
    }
  while (l.first != r.first) {
    if (l.second < r.second) {
      k -= 1ll * (a[curl] - a[curl - 1]) * l.second;
      if (k <= 0) {
        k += 1ll * (a[curl] - a[curl - 1]) * l.second;
        l.first += k / l.second;
        break;
      }
      l.first = a[curl], l.second++, curl++;
    } else {
      k -= 1ll * (a[curr + 1] - a[curr]) * r.second;
      if (k <= 0) {
        k += 1ll * (a[curr + 1] - a[curr]) * r.second;
        r.first -= k / r.second;
        break;
      }
      r.first = a[curr], r.second++, curr--;
    }
  }
  printf("%d\n", r.first - l.first);
}
