#include <bits/stdc++.h>
using namespace std;
long long n, k, a[500005], s[500005], l, r, L, R, coins, leftl, leftr, mn, mx,
    p1, p2, i;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  l = 1;
  r = n;
  while (l <= r) {
    int mid = (l + r) / 2;
    coins = s[n] - s[mid] - a[mid] * (n - mid);
    if (coins > k) {
      l = mid + 1;
    } else {
      r = mid - 1;
      R = mid;
    }
  }
  l = 1;
  r = n;
  while (l <= r) {
    int mid = (l + r) / 2;
    coins = a[mid] * mid - s[mid];
    if (coins > k) {
      r = mid - 1;
    } else {
      l = mid + 1;
      L = mid;
    }
  }
  leftl = a[L] * L - s[L];
  leftr = s[n] - s[R - 1] - a[R] * (n - R + 1);
  leftl = k - leftl;
  leftr = k - leftr;
  if (leftl % L) p2 = 1;
  if (leftr % (n - R + 1)) p1 = 1;
  mn = min(leftl / L + a[L], a[R] - leftr / (n - R + 1) - p1);
  mx = max(a[R] - leftr / (n - R + 1), leftl / L + a[L] + p2);
  if (L >= R && s[n] % n == 0)
    cout << 0;
  else if (L >= R && s[n] % n != 0)
    cout << 1;
  else
    cout << mx - mn;
}
