#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  long long s = 0;
  long long mx = 0, mn = 1e18;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    mx = max(1ll * a[i], mx);
    mn = min(1ll * a[i], mn);
  }
  long long l = (s + n - 1) / (n);
  long long r = mx;
  long long res1 = 0, res2 = 0;
  while (l <= r) {
    long long sum = 0;
    long long mid = (l + r) / 2;
    for (int i = 0; i < n; i++) {
      if (a[i] > mid) sum += (a[i] - mid);
    }
    if (sum <= k) {
      res1 = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  l = mn;
  r = s / n;
  while (l <= r) {
    long long sum = 0;
    long long mid = (l + r) / 2;
    for (int i = 0; i < n; i++) {
      if (a[i] < mid) sum += (mid - a[i]);
    }
    if (sum <= k) {
      res2 = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  cout << res1 - res2 << '\n';
  return 0;
}
