#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
using lli = long long int;
using llu = long long unsigned;
using pii = tuple<lli, lli>;
using piii = tuple<lli, lli, lli>;
using piiii = tuple<lli, lli, lli, lli>;
using vi = vector<lli>;
using vii = vector<pii>;
using viii = vector<piii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
using vviii = vector<viii>;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_queue = priority_queue<T>;
template <int... I>
struct my_index_sequence {
  using type = my_index_sequence;
  static constexpr array<int, sizeof...(I)> value = {I...};
};
namespace my_index_sequence_detail {
template <typename I, typename J>
struct concat;
template <int... I, int... J>
struct concat<my_index_sequence<I...>, my_index_sequence<J...>>
    : my_index_sequence<I..., (sizeof...(I) + J)...> {};
template <int N>
struct make_index_sequence
    : concat<typename make_index_sequence<N / 2>::type,
             typename make_index_sequence<N - N / 2>::type>::type {};
template <>
struct make_index_sequence<0> : my_index_sequence<> {};
template <>
struct make_index_sequence<1> : my_index_sequence<0> {};
}  // namespace my_index_sequence_detail
template <class... A>
using my_index_sequence_for =
    typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type;
template <class T, int... I>
void print_tuple(ostream& s, T const& a, my_index_sequence<I...>) {
  using swallow = int[];
  (void)swallow{0, (void(s << (I == 0 ? "" : ", ") << get<I>(a)), 0)...};
}
template <class T>
ostream& print_collection(ostream& s, T const& a) {
  s << '[';
  for (auto it = begin(a); it != end(a); ++it) {
    s << *it;
    if (it != prev(end(a))) s << " ";
  }
  return s << ']';
}
template <class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a) {
  s << '(';
  print_tuple(s, a, my_index_sequence_for<A...>{});
  return s << ')';
}
template <class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a) {
  return s << "(" << get<0>(a) << ", " << get<1>(a) << ")";
}
template <class T, int I>
ostream& operator<<(ostream& s, array<T, I> const& a) {
  return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, vector<T> const& a) {
  return print_collection(s, a);
}
template <class T, class U>
ostream& operator<<(ostream& s, multimap<T, U> const& a) {
  return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, multiset<T> const& a) {
  return print_collection(s, a);
}
template <class T, class U>
ostream& operator<<(ostream& s, map<T, U> const& a) {
  return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, set<T> const& a) {
  return print_collection(s, a);
}
namespace std {
namespace {
template <class T>
inline void hash_combine(size_t& seed, T const& v) {
  seed ^= hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <class Tuple, size_t Index = tuple_size<Tuple>::value - 1>
struct HashValueImpl {
  static void apply(size_t& seed, Tuple const& tuple) {
    HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
    hash_combine(seed, get<Index>(tuple));
  }
};
template <class Tuple>
struct HashValueImpl<Tuple, 0> {
  static void apply(size_t& seed, Tuple const& tuple) {
    hash_combine(seed, get<0>(tuple));
  }
};
}  // namespace
template <typename... TT>
struct hash<tuple<TT...>> {
  size_t operator()(tuple<TT...> const& tt) const {
    size_t seed = 0;
    HashValueImpl<tuple<TT...>>::apply(seed, tt);
    return seed;
  }
};
}  // namespace std
int main(int, char**) {
  ios::sync_with_stdio(0);
  lli n, k;
  cin >> n >> k;
  vi C(n);
  for (lli i = 0; i < (lli)(n); ++i) cin >> C[i];
  sort(begin(C), end(C));
  lli s = 0;
  for (lli i = 0; i < (lli)(n); ++i) s += C[i];
  lli a, b;
  {
    lli i = 0, v = C[i];
    lli rk = k;
    while (1) {
      if (i < n - 1) {
        lli w = C[i + 1];
        lli cost = (w - v) * (i + 1);
        if (cost <= rk) {
          v = w;
          rk -= cost;
          i += 1;
        } else {
          v += rk / (i + 1);
          break;
        }
      } else {
        break;
      }
    }
    a = v;
  }
  {
    lli i = n - 1, v = C[i];
    lli rk = k;
    while (1) {
      if (i > 0) {
        lli w = C[i - 1];
        lli cost = (v - w) * (n - i);
        if (cost <= rk) {
          v = w;
          rk -= cost;
          i -= 1;
        } else {
          v -= rk / (n - i);
          break;
        }
      } else {
        break;
      }
    }
    b = v;
  }
  lli r = b - a;
  if (r <= 0) {
    r = 0;
    if (s % n != 0) r = 1;
  }
  cout << r << endl;
  return 0;
}
