#include <bits/stdc++.h>
using namespace std;
long long a[500010];
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  sort(a + 1, a + 1 + n);
  long long L, R, l, r, p1 = a[1], p2 = a[n];
  L = sum / n;
  R = (sum + n - 1) / n;
  l = a[1], r = L;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long cnt = 0;
    for (int i = 1; a[i] <= mid && i <= n; i++) {
      if (mid > a[i]) {
        cnt += (mid - a[i]);
      }
    }
    if (cnt <= k) {
      p1 = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  l = R, r = a[n];
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long cnt = 0;
    for (int i = n; a[i] >= mid && i >= 1; i--) {
      if (a[i] > mid) {
        cnt += (a[i] - mid);
      }
    }
    if (cnt <= k) {
      p2 = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  printf("%lld\n", p2 - p1);
  return 0;
}
