#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
inline bool Min(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool Max(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline ll nl() {
  ll a;
  scanf("%lld", &a);
  return a;
}
inline double nd() {
  double a;
  scanf("%lf", &a);
  return a;
}
inline void pi(int a) { printf("%d ", a); }
inline void pl(ll a) { printf("%lld ", a); }
inline void pd(double a) { printf("%.12lf ", a); }
const int N = 5e5 + 100;
int a[N];
int n, k;
bool checkPref(ll val) {
  ll sum = 0;
  for (int i = 0; i < (int)(n); ++i) sum += max(0LL, val - a[i]);
  return sum <= k;
}
bool checkSuff(ll val) {
  ll sum = 0;
  for (int i = 0; i < (int)(n); ++i) sum += max(0LL, a[i] - val);
  return sum <= k;
}
void solve() {
  n = ni();
  k = ni();
  for (int i = 0; i < (int)(n); ++i) a[i] = ni();
  sort(a, a + n);
  int ansPref = 0, ansSuff = 0;
  for (int i = 1 << 30; i; i /= 2) {
    if (checkPref(a[0] + (ansPref + i))) ansPref += i;
    if (checkSuff(a[n - 1] - (ansSuff + i))) ansSuff += i;
  }
  ansPref = a[0] + ansPref;
  ansSuff = a[n - 1] - ansSuff;
  ll sum = 0;
  for (int i = 0; i < (int)(n); ++i) sum += a[i];
  if (ansPref >= ansSuff) {
    if (sum % n == 0)
      cout << 0;
    else
      cout << 1;
    return;
  }
  cout << ansSuff - ansPref;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand((int)clock());
  solve();
  return 0;
}
