#include <bits/stdc++.h>
using namespace std;
int v[500500];
int main() {
  int n;
  long long k, s = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%d", v + i), s += v[i];
  sort(v, v + n);
  long long inf = s / n;
  long long sup = inf + (s % n != 0);
  if (inf == sup) {
    long long u = 0;
    for (int i = 0; i < n; i++)
      if (v[i] > inf) u += v[i] - inf;
    ;
    if (u <= k) {
      printf("0\n");
      return 0;
    }
  }
  int up = n - 1;
  long long cur = 1;
  long long aux = k;
  while (up >= 1 && v[up - 1] >= sup && cur * (v[up] - v[up - 1]) <= aux) {
    aux -= cur * (v[up] - v[up - 1]);
    cur++;
    up--;
  }
  long long B = v[up] - aux / cur;
  if (B < sup) B = sup;
  int low = 0;
  cur = 1;
  aux = k;
  while (low <= n - 2 && v[low + 1] <= inf &&
         cur * (v[low + 1] - v[low]) <= aux) {
    aux -= cur * (v[low + 1] - v[low]);
    cur++;
    low++;
  }
  long long A = v[low] + aux / cur;
  if (A > inf) A = inf;
  cout << B - A << endl;
}
