#include <bits/stdc++.h>
using namespace std;
const int Max = 3e5 + 3, Mod = 1e9 + 7;
bool cnt[2];
int n, k;
map<int, int> m;
vector<pair<int, int> > a;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
  }
  for (auto i : m) a.push_back(i);
  int l = -10, r = 1e9, mid, up, down;
  while (l <= r) {
    mid = l + r >> 1;
    long long sum = 0;
    for (auto i : a)
      if (i.first <= mid) sum += (long long)(mid - i.first) * i.second;
    if (sum <= k)
      l = mid + 1, down = mid;
    else
      r = mid - 1;
  }
  l = -10, r = 1e9;
  while (l <= r) {
    mid = l + r >> 1;
    long long sum = 0;
    for (auto i : a)
      if (i.first >= mid) sum += (long long)(i.first - mid) * i.second;
    if (sum <= k)
      r = mid - 1, up = mid;
    else
      l = mid + 1;
  }
  if (up > down)
    cout << up - down << endl;
  else {
    l = -10;
    r = 1e9;
    int ans;
    while (l <= r) {
      mid = l + r >> 1;
      long long sum1 = 0, sum2 = 0;
      for (auto i : a)
        if (i.first < mid)
          sum1 += (long long)(mid - i.first) * i.second;
        else
          sum2 += (long long)(i.first - mid) * i.second;
      if (sum1 <= sum2)
        l = mid + 1, ans = sum2 - sum1;
      else
        r = mid - 1;
    }
    cout << (ans > 0) << endl;
  }
  return 0;
}
