#include <bits/stdc++.h>
using namespace std;
const long long inf = 4e18;
const long long maxn = 5e5 + 30;
const long long mod = 1e9 + 7;
const long long Big = 1e9 + 10;
#pragma GCC Optimize("Ofast")
long long a[maxn], n, k, sm;
map<long long, long long> mp;
vector<long long> v, vs, vc;
long long mx, mn;
long long h = 1;
long long dn, up;
long long Cnt_Min(long long val) {
  long long l = 0, r = (v).size() - 1, ind = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (v[mid] < val) {
      ind = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  if (ind == -1) return 0;
  return (val * vc[ind]) - (vs[ind]);
}
long long Cnt_Max(long long val) {
  long long l = 0, r = (v).size() - 1, ind = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (v[mid] <= val) {
      ind = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  if (ind == -1) return -1;
  return (sm - vs[ind]) - (val * (n - vc[ind]));
}
long long calc_min() {
  long long l = mn, r = dn, ans = l;
  if (l == r) return ans;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long num = Cnt_Min(mid);
    if (num != -1 && num <= k) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ans;
}
long long calc_max() {
  long long l = up, r = mx, ans = l;
  if (l == r) return ans;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long num = Cnt_Max(mid);
    if (num != -1 && num <= k) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ans;
}
int main() {
  cin >> n >> k;
  mx = -inf;
  mn = inf;
  for (long long i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    mn = min(mn, x);
    mx = max(mx, x);
    sm += x;
    mp[x]++;
  }
  dn = sm / n;
  up = (sm / n) + (sm % n != 0);
  for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();
       it++) {
    v.push_back(it->first);
    if ((v).size() != 1) {
      vc.push_back(vc.back() + (it->second));
      vs.push_back(vs.back() + ((it->second) * (it->first)));
    } else {
      vc.push_back(it->second);
      vs.push_back((it->second) * (it->first));
    }
  }
  cout << calc_max() - calc_min();
}
