#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e5 + 5;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long long mod = (int)1e9 + 7;
long long n, k, a[MAXN];
bool check(long long x) {
  long long sum = 0;
  for (int i = (1); i <= (n); i++)
    if (a[i] > x) sum += a[i] - x;
  return k >= sum;
}
bool check2(long long x) {
  long long sum = 0;
  for (int i = (1); i <= (n); i++)
    if (x > a[i]) sum += x - a[i];
  return k >= sum;
}
int main() {
  cin >> n >> k;
  long long sum = 0;
  for (int i = (1); i <= (n); i++) cin >> a[i], sum += a[i];
  long long up, down, ans1, ans2;
  if (sum % n == 0)
    up = down = sum / n;
  else
    up = sum / n, down = up + 1;
  long long l = 1, r = up, mid;
  while (l <= r) {
    mid = l + r >> 1;
    if (check2(mid))
      l = mid + 1, ans1 = mid;
    else
      r = mid - 1;
  }
  l = down, r = INF;
  while (l <= r) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid - 1, ans2 = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans2 - ans1);
  return 0;
}
