#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  int l = 1, r = n;
  int left = 1, right = 1;
  while (k > 0 && l != r) {
    if (left >= right) {
      if (k >= right * (a[r] - a[r - 1])) {
        k = k - right * (a[r] - a[r - 1]);
        right++;
        r--;
      } else {
        a[r] = a[r] - k / right;
        break;
      }
    } else {
      if (k >= left * (a[l + 1] - a[l])) {
        k = k - left * (a[l + 1] - a[l]);
        l++;
        left++;
      } else {
        a[l] = a[l] + k / left;
        break;
      }
    }
  }
  cout << a[r] - a[l];
}
