#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(), cout.tie();
  long long n, k;
  cin >> n >> k;
  long long a[n];
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a, a + n);
  int i = 0, j = n - 1;
  long long mini = a[0], maxi = a[n - 1];
  while (k && i < j) {
    while (i + 1 < n && a[i] == a[i + 1]) i++;
    while (j - 1 >= 0 && a[j] == a[j - 1]) j--;
    if (i < j) {
      long long x = mp[a[i]], y = mp[a[j]];
      if (x < y) {
        long long d = a[i + 1] - a[i];
        long long mn = min(k / x, d);
        if ((a[i] + mn) == a[i + 1]) {
          mp[a[i + 1]] += mp[a[i]];
          k -= (mn * mp[a[i]]);
          mini = a[i + 1];
          i++;
        } else {
          mini = a[i] + mn;
          break;
        }
      } else {
        long long d = a[j] - a[j - 1];
        long long mn = min(k / y, d);
        if ((a[j] - mn) == a[j - 1]) {
          mp[a[j - 1]] += mp[a[j]];
          k -= (mn * mp[a[j]]);
          maxi = a[j - 1];
          j--;
        } else {
          maxi = a[j] - mn;
          break;
        }
      }
    } else {
      mini = a[i], maxi = a[i];
    }
  }
  cout << maxi - mini << endl;
  return 0;
}
