#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 20;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double RATE = 0.995;
const double eps = 1e-4;
int arr[MAXN];
signed main() {
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
  }
  sort(arr + 1, arr + 1 + n);
  long long ans = arr[n] - arr[1];
  for (int i = 1; i < (n + 1) / 2; ++i) {
    long long t =
        min(1ll * (arr[n - i + 1] - arr[n - i] + arr[i + 1] - arr[i]), k / i);
    ans -= t;
    k -= i * t;
  }
  if (n % 2 == 0) {
    long long t = min(1ll * (arr[n / 2 + 1] - arr[n / 2]), k / (n / 2));
    ans -= t;
  }
  printf("%lld\n", ans);
  return 0;
}
