#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int* arr = new long long int[n];
  for (long long int i = 0; i < n; ++i) cin >> arr[i];
  sort(arr, arr + n);
  long long int ans = arr[n - 1] - arr[0];
  long long int be = 0, end = n - 1;
  while (be < end && k) {
    long long int no_of_changes = 0;
    if (be < n - end) {
      ++be;
      long long int diff = arr[be] - arr[be - 1];
      no_of_changes = be * diff;
      if (no_of_changes <= k) {
        k -= no_of_changes;
        ans -= diff;
      } else {
        no_of_changes = k / be;
        k = 0;
        ans -= no_of_changes;
      }
    } else {
      --end;
      long long int diff = arr[end + 1] - arr[end];
      no_of_changes = (n - end - 1) * diff;
      if (no_of_changes <= k) {
        k -= no_of_changes;
        ans -= diff;
      } else {
        no_of_changes = k / (n - end - 1);
        k = 0;
        ans -= no_of_changes;
      }
    }
  }
  cout << ans;
}
