#include <bits/stdc++.h>
using namespace std;
long long t;
int a[1000000], i, j, k, n, m, x, y, z;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  int l = 1;
  int r = 2 * 2e9;
  while (l < r) {
    int mid = ((long long)l + r) / 2;
    if (l == mid) mid++;
    t = 0;
    for (i = 1; i <= n; i++) t += max(0, mid - a[i]);
    if (t <= k)
      l = mid;
    else
      r = mid - 1;
  }
  t = k;
  for (i = 1; i <= n; i++) {
    t -= max(0, l - a[i]);
    a[i] = max(a[i], l);
  }
  for (i = 1; i <= n; i++)
    if (a[i] == l and t) {
      t--;
      a[i]++;
    }
  l = 1, r = 2 * 2e9;
  while (l < r) {
    int mid = ((long long)l + r) / 2;
    t = 0;
    for (i = 1; i <= n; i++) t += max(0, a[i] - mid);
    if (t <= k)
      r = mid;
    else
      l = mid + 1;
  }
  t = k;
  for (i = 1; i <= n; i++) {
    t -= max(0, a[i] - l);
    a[i] = min(a[i], l);
  }
  for (i = 1; i <= n; i++)
    if (a[i] == l and t) {
      t--;
      a[i]--;
    }
  cout << *max_element(a + 1, a + 1 + n) - *min_element(a + 1, a + 1 + n)
       << endl;
}
