#include <bits/stdc++.h>
using namespace std;
int getn() {
  int h;
  scanf("%d", &h);
  return h;
}
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U>& par) {
  cout << "[" << par.first << ";" << par.second << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
  return out;
}
bool ccw(complex<long double> p, complex<long double> a,
         complex<long double> b) {
  if ((conj(a - p) * (b - p)).imag() <= 0)
    return (0);
  else
    return (1);
}
int main() {
  int n = getn();
  long long int k = getn();
  int front = -1, back = n;
  vector<long long int> coins;
  long long int average = 0;
  for (int i = 0; i < n; i++) {
    coins.push_back(getn());
    average += coins[i];
  }
  long long int h = average / n;
  long long int prec = -(average % h);
  for (int i = 0; i < coins.size(); i++) prec += abs(h - coins[i]);
  if (k >= prec / 2) {
    if (0) cout << "Now " << endl;
    cout << (average % n ? 1 : 0) << endl;
    return 0;
  }
  sort(coins.begin(), coins.end());
  long long int steps = -1;
  while (steps < k) {
    steps = max(steps, (long long int)0);
    front++;
    steps += (front + 1) * (coins[front + 1] - coins[front]);
  }
  if (0) cout << "Front " << front << endl;
  steps = -1;
  while (steps < k) {
    steps = max((long long int)0, steps);
    back--;
    steps += (n - back) * (coins[back] - coins[back - 1]);
  }
  if (0) cout << "Back " << back << endl;
  long long int min_val = k;
  for (int i = 0; i < front + 1; i++) min_val += coins[i];
  long long int mini = min_val / (front + 1);
  long long int maxi = -k;
  for (int i = 0; i < n - back; i++) maxi += coins[n - 1 - i];
  long long int maxV = maxi / (n - back) + (maxi % (n - back) ? 1 : 0);
  cout << maxV - mini << endl;
}
