#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
  stringstream ss;
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
  o << "(" << t.first << ", " << t.second << ")";
  return o;
}
template <class T>
inline string tostring(T first) {
  _.ss.clear();
  _.ss.str("");
  _.ss << first;
  return _.ss.str();
}
template <class T>
inline T convert(const string &s) {
  char *p;
  if (is_integral<T>())
    return strtoll(s.c_str(), &p, 10);
  else
    return strtod(s.c_str(), &p);
}
template <class T>
void PV(T a, T b, int p = 0, int w = 0, string s = " ") {
  int c = 0;
  while (a != b) {
    cout << setw(w) << *a++;
    cout << ((a != b && (!p || ++c % p)) ? s : "\n");
  }
  cout.flush();
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 500010;
long long n, k;
long long c[N];
long long s[N];
int check(long long first) {
  for (int i = 1; i < n; i++) {
    if (c[i] > first || c[i + 1] < first) continue;
    long long needL = i * first - s[i];
    long long hasR = s[n] - s[i] - (n - i) * first;
    if (needL <= k && needL <= hasR) return 1;
  }
  return 0;
}
int getmin() {
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + c[i];
  long long L = c[1], R = c[n];
  while (L < R) {
    long long M = (L + R + 1) / 2;
    if (check(M))
      L = M;
    else
      R = M - 1;
  }
  return L;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> c[i];
  sort(c + 1, c + n + 1);
  long long t1 = getmin();
  reverse(c + 1, c + n + 1);
  for (int i = 1; i <= n; i++) c[i] = -c[i];
  long long t2 = -getmin();
  cout << t2 - t1 << endl;
  return 0;
}
