#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
const int mx = 1 << 29;
long long ans, sum, t, n, k, m, ar[1000005], rtmp, ltmp;
int dx[] = {0, 1, -1, 0, 0};
int dy[] = {0, 0, 0, 1, -1};
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &ar[i]);
    sum += ar[i];
  }
  sort(ar + 1, ar + n + 1);
  m = k;
  for (int i = 2; i <= n; i++) {
    if ((ar[i] - ar[i - 1]) * (i - 1) <= m) {
      m -= (ar[i] - ar[i - 1]) * (i - 1);
      ltmp = ar[i];
    } else {
      ltmp = ar[i - 1] + m / (i - 1);
      m = 0;
      break;
    }
  }
  m = k;
  for (int i = n - 1, j = 1; i >= 1; i--, j++) {
    if ((ar[i + 1] - ar[i]) * j <= m) {
      m -= (ar[i + 1] - ar[i]) * j;
      rtmp = ar[i];
    } else {
      rtmp = ar[i + 1] - m / j;
      m = 0;
      break;
    }
  }
  if (ltmp >= rtmp) {
    if (sum % n)
      printf("1\n");
    else
      printf("0\n");
  } else {
    cout << rtmp - ltmp << "\n";
  }
  return 0;
}
