#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
long long int inp[500005];
long long int pure[500005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int s = 0, n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> inp[i];
    s += inp[i];
  }
  sort(inp, inp + n);
  long long int val = s / n;
  for (int i = 0; i < n; i++) pure[i] = val;
  for (int i = 0; i < s % n; i++) pure[i]++;
  reverse(pure, pure + n);
  long long int l, r, mn, mx, opr;
  l = inp[0];
  r = pure[0] + 1;
  while (l + 1 < r) {
    long long int mid = (l + r) >> 1;
    opr = 0;
    for (int i = 0; i < n; i++) opr += max(mid, inp[i]) - inp[i];
    if (opr <= k)
      l = mid;
    else
      r = mid;
  }
  mn = l;
  l = pure[n - 1] - 1;
  r = inp[n - 1];
  while (l + 1 < r) {
    long long int mid = (l + r) >> 1;
    opr = 0;
    for (int i = 0; i < n; i++) opr += inp[i] - min(mid, inp[i]);
    if (opr <= k)
      r = mid;
    else
      l = mid;
  }
  mx = r;
  cout << mx - mn << "\n";
  return 0;
}
