#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.0000000001;
using namespace std;
int T[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n;
  long long int k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> T[i];
  sort(T + 1, T + n + 1);
  int a = 1, b = 1;
  long long int last = k;
  int licznik = 0;
  while (k) {
    if (a == n - b + 1) break;
    if (a <= b) {
      long long int ile = min(k / a, (long long int)(T[a + 1] - T[a]));
      k -= ile * a;
      T[a] += ile;
      while (T[a] == T[a + 1] && a != n - b + 1) a++;
    } else {
      long long int ile = min(k / b, (long long int)(T[n - b + 1] - T[n - b]));
      k -= ile * b;
      T[n - b + 1] -= ile;
      while (T[n - b + 1] == T[n - b] && n - b + 1 != a) b++;
    }
    if (last == k)
      licznik++;
    else
      licznik = 0;
    if (licznik > 100) break;
    last = k;
  }
  cout << T[n - b + 1] - T[a];
  return 0;
}
