#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const long long int MAXN = 1e5 + 10;
long long int a[MAXN];
long long int n, k;
long long int high[MAXN], low[MAXN];
void solve() {
  cin >> n >> k;
  for (long long int i = (1); i <= (n); ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  long long int sum = 1;
  for (long long int i = (2); i <= (n); ++i) {
    long long int num = a[i] - a[i - 1];
    high[i] = high[i - 1] + num * sum;
    sum++;
  }
  sum = 1;
  for (long long int i = (n - 1); i >= (1); --i) {
    long long int num = a[i + 1] - a[i];
    low[i] = low[i + 1] + num * sum;
    sum++;
  }
  long long int ans = a[n] - a[1];
  long long int second = 1, e = n;
  long long int prev_sum = 1, ahead_sum = 1;
  while (second <= e) {
    if (prev_sum >= ahead_sum) {
      if (ahead_sum * (a[e] - a[e - 1]) <= k) {
        k = k - ahead_sum * (a[e] - a[e - 1]);
        e--;
        ans = min(ans, a[e] - a[second]);
        ahead_sum++;
      } else {
        long long int jaana = k / (ahead_sum);
        ans = min(ans, a[e] - jaana - a[second]);
        break;
      }
    } else {
      if (prev_sum * (a[second + 1] - a[second]) <= k) {
        k = k - prev_sum * (a[second + 1] - a[second]);
        second++;
        ans = min(ans, a[e] - a[second]);
        prev_sum++;
      } else {
        long long int jaana = k / (prev_sum);
        ans = min(ans, a[e] - jaana - a[second]);
        break;
      }
    }
  }
  ans = max(ans, 0LL);
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  for (long long int i = (1); i <= (t); ++i) {
    solve();
  }
}
