#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end());
  long long l = 0, r = sum / n;
  long long minn = 0;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    long long sum1 = 0;
    for (long long i = 0; i < n; i++) sum1 += max((long long)0, mid - a[i]);
    if (sum1 <= k) {
      minn = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  l = (sum + n - 1) / n;
  r = 1e9;
  long long maxx = 0;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    long long sum1 = 0;
    for (long long i = 0; i < n; i++) sum1 += max((long long)0, a[i] - mid);
    if (sum1 <= k) {
      maxx = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << maxx - minn << endl;
}
int32_t main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
