#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int arr[N];
int n, k;
int mnm = -1;
int mxm = -1;
long long sum;
void input() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n);
}
void solve() {
  int K = k;
  for (int i = 0; i < n;) {
    int j = i;
    for (; j < n && arr[i] == arr[j]; ++j)
      ;
    int dif = arr[j] - arr[i];
    int cnt = j;
    if (K >= 1ll * dif * cnt) {
      K -= 1ll * dif * cnt;
    } else {
      mnm = arr[i] + K / j;
      break;
    }
    i = j;
  }
  K = k;
  for (int i = n - 1; i >= 0;) {
    int j = i;
    for (; j >= 0 && arr[i] == arr[j]; --j)
      ;
    int dif = arr[i] - arr[j];
    int cnt = n - 1 - j;
    if (K >= 1ll * dif * cnt) {
      K -= 1ll * dif * cnt;
    } else {
      mxm = arr[i] - K / cnt;
      break;
    }
    i = j;
  }
  if (mnm == -1) mnm = arr[n - 1];
  if (mxm == -1) mxm = arr[0];
  if (mnm >= mxm) {
    if (sum % n) {
      cout << "1\n";
    } else {
      cout << "0\n";
    }
  } else {
    cout << mxm - mnm << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
