#include <bits/stdc++.h>
using namespace std;
long long a[500010];
int main() {
  long long n, k;
  int i, j;
  while (scanf("%lld%lld", &n, &k) != EOF) {
    long long sum = 0;
    long long maxx = 0, minn = 0x3f3f3f3f;
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      sum += a[i];
      maxx = max(maxx, a[i]);
      minn = min(minn, a[i]);
    }
    sort(a, a + n);
    long long la = sum / n;
    long long l = minn, r = la, ans1 = 0;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long kk = 0;
      for (i = 0; i < n; i++) {
        if (mid >= a[i]) kk += mid - a[i];
      }
      if (kk <= k)
        ans1 = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    l = (sum + n - 1) / n;
    r = maxx;
    long long ans2 = 0;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      long long kk = 0;
      for (i = 0; i < n; i++) {
        if (mid <= a[i]) kk += a[i] - mid;
      }
      if (kk <= k)
        ans2 = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    printf("%lld\n", ans2 - ans1);
  }
  return 0;
}
