#include <bits/stdc++.h>
using namespace std;
const int M = 500005;
const int mod = 1e9 + 7;
long long n, k, a[M], sum, mid, mn, ma;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  mid = sum / n;
  long long cur = 0;
  int id1 = -1;
  for (int i = 1; i < n; ++i) {
    if ((a[i] - a[i - 1]) * i + cur > k) {
      id1 = i;
      break;
    }
    if (a[i] >= mid + (mid * n != sum))
      return cout << (mid * n != sum) << "\n", 0;
    cur += (a[i] - a[i - 1]) * i;
  }
  mn = a[id1 - 1] + (k - cur) / id1;
  if (mn >= mid + (mid * n != sum)) return cout << (mid * n != sum) << "\n", 0;
  cur = 0;
  int id2 = -1;
  for (int i = n - 2; i >= 0; --i) {
    if ((a[i + 1] - a[i]) * (n - i - 1) + cur > k) {
      id2 = i;
      break;
    }
    cur += (a[i + 1] - a[i]) * (n - i - 1);
  }
  ma = a[id2 + 1] - (k - cur) / (n - id2 - 1);
  if (mn == ma)
    cout << (mid * n != sum) << "\n";
  else
    cout << ma - mn << "\n";
  return 0;
}
