#include <bits/stdc++.h>
using namespace std;
const int N = 555555;
int n, k;
int c[N];
void solve() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", c + i);
  long long sum = 0;
  for (int i = 0; i < n; ++i) sum += c[i];
  sort(c, c + n);
  if (n == 1 || c[0] == c[n - 1]) {
    cout << 0 << endl;
    return;
  }
  long long a = -1, b = -1;
  long long q = 0;
  for (int i = 0; i + 1 < n; ++i) {
    if (c[i] < c[i + 1]) {
      long long days = 1LL * (c[i + 1] - c[i]) * (i + 1);
      if (q + days < k)
        q += days;
      else {
        a = c[i] + (k - q) / (i + 1);
        break;
      }
    }
  }
  q = 0;
  for (int i = n - 1; i - 1 >= 0; --i) {
    if (c[i - 1] < c[i]) {
      long long days = 1LL * (c[i] - c[i - 1]) * (n - i);
      if (q + days < k)
        q += days;
      else {
        b = c[i] - (k - q) / (n - i);
        break;
      }
    }
  }
  if (a >= b)
    cout << (sum % n != 0) << endl;
  else
    cout << (b - a) << endl;
}
int main() {
  solve();
  return 0;
}
