#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
unordered_map<long long, long long> mp;
long long a[N];
signed main() {
  ios::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long len = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (!mp[x]) a[len++] = x;
    mp[x]++;
  }
  sort(a, a + len);
  long long l = 0, r = len - 1;
  while (l < r) {
    long long a1 = mp[a[l]], b = mp[a[r]];
    long long x = 1LL * (a[l + 1] - a[l]) * mp[a[l]];
    long long y = 1LL * (a[r] - a[r - 1]) * mp[a[r]];
    if (a1 < b) {
      if (x <= k) {
        k -= x;
        mp[a[l + 1]] += mp[a[l]];
        l++;
      } else {
        long long mid = k / a1;
        a[l] += mid;
        cout << a[r] - a[l] << endl;
        return 0;
      }
    } else {
      if (y <= k) {
        k -= y;
        mp[a[r - 1]] += mp[a[r]];
        r--;
      } else {
        long long mid = k / b;
        a[r] -= mid;
        cout << a[r] - a[l] << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
}
