#include <bits/stdc++.h>
using namespace std;
long long v[500100];
int main() {
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  sort(v + 1, v + n + 1);
  long long left = 1, right = n;
  long long nr1 = 0, nr2 = 0;
  while (v[left] == v[1]) {
    nr1++;
    left++;
  }
  left--;
  while (v[right] == v[n]) {
    nr2++;
    right--;
  }
  right++;
  long long need1 = (v[left + 1] - v[left]) * nr1;
  long long need2 = (v[right] - v[right - 1]) * nr2;
  long long v1 = 0, v2 = 0;
  if (k == 0) {
    cout << v[n] - v[1] << '\n';
    return 0;
  }
  if (v[left] == v[right]) {
    cout << "0\n";
    return 0;
  }
  int maxx = 1;
  if (sum % n == 0) maxx = 0;
  while (1) {
    if (left == right - 1 || (k < need1 - v1 && k < need2 - v2)) {
      cout << max((long long)maxx,
                  (v[right] - (k + v2) / nr2) - (v[left] + (k + v1) / nr1));
      return 0;
    } else {
      if (need1 - v1 < need2 - v2) {
        v2 += (need1 - v1);
        left++;
        nr1++;
        while (v[left + 1] == v[left]) {
          left++;
          nr1++;
        }
        k -= (need1 - v1);
        need1 = (v[left + 1] - v[left]) * nr1;
        if (v2 == need2 && left != right - 1) {
          right--;
          nr2++;
          while (v[right - 1] == v[right]) {
            right--;
            nr2++;
          }
          need2 = (v[right] - v[right - 1]) * nr2;
          if (left == right) right++;
          if (left + 1 != right) v2 = 0;
        }
        v1 = 0;
      } else {
        v1 += (need2 - v2);
        right--;
        nr2++;
        while (v[right - 1] == v[right] && right - 1 > left) {
          right--;
          nr2++;
        }
        k -= (need2 - v2);
        need2 = (v[right] - v[right - 1]) * nr2;
        if (v1 == need1 && left != right - 1) {
          left++;
          nr1++;
          while (v[left + 1] == v[left] && left + 1 < right) {
            left++;
            nr1++;
          }
          need1 = (v[left + 1] - v[left]) * nr1;
          if (left == right) left--;
          if (left + 1 != right) v1 = 0;
        }
        v2 = 0;
      }
    }
  }
  return 0;
}
