#include <bits/stdc++.h>
using namespace std;
long long int arr[1000001];
string str;
int main() {
  ios::sync_with_stdio(false);
  cin.clear();
  long long int t, n, i, j, ans = 0, count = 0, sum = 0, k, m, avg, temp,
                            minans = 0, tempk, maxans = 0;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  if (n == 1) {
    cout << arr[0];
    return 0;
  }
  avg = sum / n;
  sort(arr + 1, arr + n + 1);
  tempk = k;
  minans = arr[1];
  for (i = 1; i < n; i++) {
    if (arr[i] > avg) break;
    if (tempk == 0) break;
    temp = arr[i + 1] - arr[i];
    temp *= i;
    if (temp != 0) {
      if (tempk < temp) {
        minans = arr[i] + tempk / i;
        tempk = 0;
      } else {
        tempk -= temp;
        minans = arr[i + 1];
      }
    }
    minans = min(minans, avg);
  }
  tempk = k;
  maxans = arr[n];
  for (i = n, j = 1; i > 1; i--, j++) {
    if (arr[i] < avg) break;
    if (tempk == 0) break;
    temp = arr[i] - arr[i - 1];
    temp *= j;
    if (temp != 0) {
      if (tempk < temp) {
        maxans = arr[i] - tempk / j;
        tempk = 0;
      } else {
        tempk -= temp;
        maxans = arr[i - 1];
      }
      maxans = max(maxans, avg);
    }
  }
  if (maxans == avg && minans == avg) {
    if (sum % n)
      cout << 1;
    else
      cout << 0;
    return 0;
  }
  cout << maxans - minans;
}
