#include <bits/stdc++.h>
using namespace std;
long long N, K;
long long C[500000];
vector<pair<long long, long long> > xs;
long long front() {
  long long k = K;
  long long n = xs[0].second, b = xs[0].first;
  for (long long i = 0; i < (long long)xs.size() - 1; i++) {
    long long s = max(0LL, min(k / n, xs[i + 1].first - xs[i].first));
    if (s == 0) break;
    b += s;
    k -= s * n;
    n += xs[i + 1].second;
  }
  return b;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  long long sum = 0;
  for (long long i = 0; i < (N); i++) {
    cin >> C[i];
    sum += C[i];
  }
  sort(C, C + N);
  for (long long i = 0; i < (N); i++)
    xs.push_back(pair<long long, long long>(C[i], 0));
  sort((xs).begin(), (xs).end());
  xs.erase(unique((xs).begin(), (xs).end()), (xs).end());
  for (long long i = 0; i < (N); i++) {
    lower_bound((xs).begin(), (xs).end(), pair<long long, long long>(C[i], 0))
        ->second++;
  }
  long long l = front();
  for (long long i = 0; i < (N); i++)
    xs[i] = pair<long long, long long>(-xs[i].first, xs[i].second);
  reverse((xs).begin(), (xs).end());
  long long r = -front();
  long long ans = max(r - l, 0LL);
  if (sum % N != 0) ans = max(ans, 1LL);
  cout << ans << "\n";
  return 0;
}
