#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = 2147483647;
pair<long long, long long> cnt[10000000];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> arr(n);
  map<long long, long long> C;
  for (__typeof(0) i = (0); i < (n); ++i) {
    int x;
    scanf("%d", &arr[i]);
    C[arr[i]]++;
  }
  int l = 10000000 / 2, r = 10000000 / 2 - 1;
  for (__typeof((C).begin()) it = (C).begin(); it != (C).end(); ++it) {
    cnt[++r] = *it;
  }
  int iters = 0;
  while (true) {
    iters++;
    pair<long long, long long> a = cnt[l], b = cnt[r];
    if (a.second == 0) {
      l++;
      continue;
    }
    if (b.second == 0) {
      r--;
      continue;
    }
    if (k == 0) {
      break;
    }
    if (r - l + 1 < 2) {
      break;
    }
    long long nxt = cnt[l + 1].first, prev = cnt[r - 1].first;
    if (r - l + 1 == 2) {
      if (a.first + 1 >= b.first) {
        break;
      }
      long long mid = (a.first + b.first) / 2;
      nxt = mid;
      prev = mid;
    }
    long long need = (nxt - a.first) * a.second,
              have = (b.first - prev) * b.second;
    long long take = min(need, have);
    take = min(take, (long long)k);
    k -= take;
    {
      long long div = take / a.second, mod = take % a.second;
      l++;
      long long add = div;
      if (mod != 0) {
        if (l <= r && cnt[l].first == a.first + add + 1) {
          cnt[l].second += mod;
        } else {
          cnt[--l] = pair<int, int>(a.first + add + 1, mod);
        }
      }
      if (l <= r && cnt[l].first == a.first + add) {
        cnt[l].second += a.second - (mod);
      } else {
        cnt[--l] = pair<int, int>(a.first + add, a.second - (mod));
      }
    }
    {
      long long div = take / b.second, mod = take % b.second;
      r--;
      long long add = div;
      if (mod != 0) {
        if (l <= r && cnt[r].first == b.first - add - 1) {
          cnt[r].second += mod;
        } else {
          cnt[++r] = pair<int, int>(b.first - add - 1, mod);
        }
      }
      if (l <= r && cnt[r].first == b.first - add) {
        cnt[r].second += b.second - (mod);
      } else {
        cnt[++r] = pair<int, int>(b.first - add, b.second - (mod));
      }
    }
  }
  cout << cnt[r].first - cnt[l].first << endl;
  return 0;
}
