#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const long long inf = 0x3f3f3f3f;
long long n, k;
long long A[maxn];
bool Judge(long long x) {
  long long cnt = 0, i = 0;
  while (A[i] <= x && i < n) cnt += x - A[i], i++;
  if (cnt > k) return false;
  long long cnt1 = 0;
  while (i < n) cnt1 += A[i] - x, i++;
  if (cnt1 < cnt) return false;
  return true;
}
long long solve_min() {
  long long lb = 0, ub = inf;
  while (lb <= ub) {
    long long mid = (lb + ub) >> 1;
    if (Judge(mid))
      lb = mid + 1;
    else
      ub = mid - 1;
  }
  return ub;
}
bool Judge1(long long x) {
  long long cnt = 0, i = n - 1;
  while (i >= 0 && A[i] >= x) cnt += A[i] - x, i--;
  if (cnt > k) return false;
  long long cnt1 = 0;
  while (i >= 0) cnt1 += x - A[i], i--;
  if (cnt1 < cnt) return false;
  return true;
}
long long solve_max() {
  long long lb = 0, ub = inf;
  while (lb <= ub) {
    long long mid = (lb + ub) >> 1;
    if (Judge1(mid))
      ub = mid - 1;
    else
      lb = mid + 1;
  }
  return lb;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%I64d", &A[i]);
  sort(A, A + n);
  long long lb = solve_min();
  long long ub = solve_max();
  cout << ub - lb << endl;
  return 0;
}
