#include <bits/stdc++.h>
using namespace std;
vector<long long int> prime_check(2e5 + 2);
vector<long long int> primes;
void Sieve() {
  for (long long int i = 2; i <= 2e5; i++) {
    if (prime_check[i]) continue;
    primes.push_back(i);
    for (long long int j = 2 * i; j <= 2e5; j += i) prime_check[j] = i;
  }
}
long long int n, k;
vector<long long int> a(500005);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  long long int s = 0;
  for (long long int i = 1; i <= n; i++) cin >> a[i], s += a[i];
  sort(a.begin() + 1, a.begin() + n + 1);
  long long int mini = s / n, maxi = s / n;
  if (s % n) maxi++;
  long long int l = a[1], r = mini;
  long long int vl = 0, vr = INT64_MAX;
  while (l <= r) {
    long long int s1 = 0;
    long long int mid = (l + r) / 2;
    for (long long int i = 1; i <= n; i++) s1 += max(0LL, mid - a[i]);
    if (s1 <= k)
      l = mid + 1, vl = max(vl, mid);
    else
      r = mid - 1;
  }
  l = maxi, r = a[n];
  while (l <= r) {
    long long int s1 = 0;
    long long int mid = (l + r) / 2;
    for (long long int i = 1; i <= n; i++) s1 += max(0LL, a[i] - mid);
    if (s1 <= k)
      r = mid - 1, vr = min(vr, mid);
    else
      l = mid + 1;
  }
  cout << vr - vl << "\n";
}
