#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1e5 + 5;
long long n, k;
long long c[maxn];
long long ansl, ansr;
int judgemi(long long x) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] > x) break;
    sum += x - c[i];
  }
  if (sum <= k) return 1;
  return 0;
}
int judgemx(long long x) {
  long long sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (x > c[i]) break;
    sum += c[i] - x;
  }
  if (sum <= k) return 1;
  return 0;
}
void searchmi(long long l, long long r) {
  long long left = l, right = r, mid;
  left = l, right = r;
  while (left + 4 < right) {
    mid = (left + right) / 2;
    if (judgemi(mid))
      left = mid;
    else
      right = mid;
  }
  for (long long i = right; i >= left; i--) {
    if (judgemi(i)) {
      ansl = i;
      break;
    }
  }
}
void searchmx(long long l, long long r) {
  long long left = l, right = r, mid;
  left = l, right = r;
  while (left + 4 < right) {
    mid = (left + right) / 2;
    if (judgemx(mid))
      right = mid;
    else
      left = mid;
  }
  for (long long i = left; i <= right; i++) {
    if (judgemx(i)) {
      ansr = i;
      break;
    }
  }
}
int main() {
  while (~scanf("%lld %lld", &n, &k)) {
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &c[i]);
      sum += c[i];
    }
    sort(c, c + n);
    long long l, r, left, right, mid;
    if (sum % n == 0) {
      l = sum / n;
      r = sum / n;
    } else {
      l = sum / n;
      r = 1 + sum / n;
    }
    searchmi(0, l);
    searchmx(r, c[n - 1]);
    printf("%lld\n", ansr - ansl);
  }
  return 0;
}
