#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pi = pair<int, int>;
using vs = vector<string>;
using vpi = vector<pi>;
using ll = long long int;
template <typename T>
string tostr(T x) {
  ostringstream oss;
  oss << x;
  return oss.str();
}
template <typename T1, typename T2, typename T3>
T1 modpow(T1 a, T2 p, T3 mod) {
  T1 ret = 1;
  a %= mod;
  for (; p > 0; p /= 2) {
    if (p & 1) ret = 1ll * ret * a % mod;
    a = 1ll * a * a % mod;
  }
  return ret;
}
int dx[]{-1, 0, 1, 0, 1, 1, -1, -1};
int dy[]{0, -1, 0, 1, 1, -1, 1, -1};
constexpr auto PI = 3.14159265358979323846L;
constexpr auto oo = numeric_limits<int>::max() / 2 - 10;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr int mx_n = 500005;
int n;
int c[mx_n], k;
ll sum;
ll getLimit() {
  int hi, lo;
  hi = lo = sum / n;
  int rem = sum % n;
  if (rem) ++hi;
  sort(c, c + n);
  ll ans = 0;
  for (auto i = 0, _i = (n); i < _i; ++i) {
    if (i < n - rem) ans += abs(c[i] - lo);
    if (i >= n - rem) ans += abs(c[i] - hi);
  };
  assert(ans % 2 == 0);
  return ans / 2;
}
ll brutelimit() {
  ll ans = 0;
  multiset<int> s(c, c + n);
  int target = (sum % n == 0) ? 0 : 1;
  while (*s.rbegin() - *s.begin() != target) {
    int x = *s.rbegin();
    s.erase(s.find(x));
    s.insert(x - 1);
    int y = *s.begin();
    s.erase(s.find(y));
    s.insert(y + 1);
    ++ans;
  }
  return ans;
}
int get_max() {
  int r = k;
  map<int, int> cnt;
  set<int> pos;
  for (auto i = 0, _i = (n); i < _i; ++i) {
    pos.insert(c[i]);
    ++cnt[c[i]];
  }
  while (r) {
    int cur = *pos.rbegin();
    pos.erase(cur);
    int cur2 = *pos.rbegin();
    if (cnt[cur] > r) return cur;
    ll estimate = 1ll * cnt[cur] * min(cur - cur2, r / cnt[cur]);
    ;
    int nxt = cur - estimate / cnt[cur];
    int c = cnt[cur];
    r -= estimate;
    cnt[nxt] += c;
    cnt.erase(cur);
    pos.insert(nxt);
  }
  return *pos.rbegin();
}
int get_min() {
  int r = k;
  map<int, int> cnt;
  set<int> pos;
  for (auto i = 0, _i = (n); i < _i; ++i) {
    pos.insert(c[i]);
    ++cnt[c[i]];
  }
  int target = (sum % n == 0 ? 0 : 1);
  while (*pos.rbegin() - *pos.begin() != target && r) {
    int cur = *pos.begin();
    pos.erase(cur);
    int cur2 = *pos.begin();
    if (cnt[cur] > r) return cur;
    ll estimate = 1ll * cnt[cur] * min(cur2 - cur, r / cnt[cur]);
    int nxt = cur + estimate / cnt[cur];
    int c = cnt[cur];
    r -= estimate;
    cnt[nxt] += c;
    cnt.erase(cur);
    pos.insert(nxt);
  }
  return *pos.begin();
}
int brute() {
  multiset<int> s(c, c + n);
  for (auto kk = 0, _kk = (k); kk < _kk; ++kk) {
    int x = *s.rbegin();
    s.erase(s.find(x));
    s.insert(x - 1);
    int y = *s.begin();
    s.erase(s.find(y));
    s.insert(y + 1);
  }
  return *s.rbegin() - *s.begin();
}
int solve() {
  if (n == 1) return 0;
  sum = accumulate(c, c + n, 0ll);
  ll lim = getLimit();
  ;
  if (lim <= k) {
    return (sum % n == 0 ? 0 : 1);
  }
  int hi = get_max();
  int lo = get_min();
  ;
  return hi - lo;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (auto i = 0, _i = (n); i < _i; ++i) cin >> c[i];
  int ans = solve();
  cout << ans << endl;
  return 0;
}
