#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 7;
long long n, m, A[N], ans;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) A[i] = read();
  sort(A + 1, A + n + 1);
  ans = A[n] - A[1];
  for (int i = 1; i < (n / 2) + (n & 1); i++) {
    long long t = min(A[i + 1] - A[i] + A[n - i + 1] - A[n - i], m / i);
    ans -= t;
    m -= t * i;
  }
  if (!(n & 1)) {
    long long t = min(A[n / 2 + 1] - A[n / 2], m / (n / 2));
    ans -= t;
    m -= t * (n / 2);
  }
  printf("%lld\n", ans);
  return 0;
}
