#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  unsigned long long n, k;
  cin >> n >> k;
  unsigned long long a[n];
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  unsigned long long bot = 0, top = n - 1;
  while (true) {
    while (bot < n - 1 && a[bot + 1] == a[bot]) {
      bot++;
    }
    while (top > 0 && a[top - 1] == a[top]) {
      top--;
    }
    if (bot >= top) {
      break;
    }
    if (bot <= n - 1 - top) {
      if (bot < k) {
        unsigned long long _k = (a[bot + 1] - a[bot]) * (bot + 1);
        if (_k <= k) {
          k -= _k;
          bot++;
        } else {
          a[bot] += k / (bot + 1);
          break;
        }
      } else {
        break;
      }
    } else {
      if (n - 1 - top < k) {
        unsigned long long _k = (a[top] - a[top - 1]) * (n - top);
        if (_k <= k) {
          k -= _k;
          top--;
        } else {
          a[top] -= k / (n - top);
          break;
        }
      } else {
        break;
      }
    }
  }
  cout << a[top] - a[bot] << endl;
}
