#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
  std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
template <typename Arg1>
void outn(Arg1&& arg1) {
  cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void outn(Arg1&& arg1, Args&&... args) {
  cout << arg1 << " ";
  outn(args...);
}
template <typename Arg1>
void outs(Arg1&& arg1) {
  cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void outs(Arg1&& arg1, Args&&... args) {
  cout << arg1 << " ";
  outs(args...);
}
template <typename Arg1>
void inp(Arg1&& arg1) {
  cin >> arg1;
}
template <typename Arg1, typename... Args>
void inp(Arg1&& arg1, Args&&... args) {
  cin >> arg1;
  inp(args...);
}
inline long long int mulm(long long int a, long long int b, long long int m) {
  a = ((a % m) * (b % m)) % m;
  return a;
}
template <typename T>
T expo(T e, T n) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = x * p;
    p = p * p;
    n >>= 1;
  }
  return x;
}
template <typename T>
T powerm(T e, T n, T m) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = mulm(x, p, m);
    p = mulm(p, p, m);
    n >>= 1;
  }
  return x;
}
inline long long int subm(long long int a, long long int b, long long int m) {
  a = (a - b + m) % m;
  return a;
}
inline long long int addm(long long int a, long long int b, long long int m) {
  a = (a + b) % m;
  return a;
}
inline void unset_bit_at(long long int& n, long long int b) {
  n &= ~(1ll << b);
}
inline void set_bit_at(long long int& n, long long int b) { n |= (1ll << b); }
inline long long int is_setat(long long int n, long long int b) {
  return (n >> b) & 1;
}
inline long long int get_lastsetbit(long long int n) { return n & (-n); }
inline long long int pow2(long long int n) { return (1ll << n); }
const long long int MOD = 1000000007;
const long long int MX6 = 5000005;
const long long int MAX = 1234567;
const long long int MX5 = 500005;
const long long int INF = 1e18 + 7;
const long long int MX3 = 5005;
long long int n, k;
vector<pair<long long int, long long int> > unq;
vector<long long int> arr;
void solve() {
  inp(n, k);
  arr.resize(n + 1, 0);
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) inp(arr[i]);
  sort(arr.begin(), arr.end());
  long long int mxd = INF;
  long long int lval = arr[1], rval = arr[n], l = 1, r = n;
  while (l < r) {
    while (l < r and arr[l] == arr[l + 1]) ++l;
    while (l < r and arr[r] == arr[r - 1]) --r;
    if (l == r) break;
    long long int frw = l * (arr[l + 1] - arr[l]);
    long long int bck = (n - r + 1) * (arr[r] - arr[r - 1]);
    bool go = true;
    if (l < n - r + 1) {
      if (frw <= k) {
        k -= frw;
        ++l;
        lval = arr[l];
      } else {
        lval += k / l;
        break;
      }
    } else {
      if (bck <= k) {
        k -= bck;
        --r;
        rval = arr[r];
      } else {
        rval -= k / (n - r + 1);
        break;
      }
    }
  }
  outs(rval - lval);
}
int32_t main() {
  long long int t;
  t = 1;
  cin.sync_with_stdio(0), cin.tie(0);
  while (t--) {
    solve();
    cout << "\n";
    ;
  }
  return 0;
}
