#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int n) {
  long long int r;
  if (n == 0)
    return 1;
  else if (n == 1)
    return a;
  else
    r = power(a, n / 2);
  if (n % 2 == 0)
    return ((r) % 1000000007) * ((r) % 1000000007) % 1000000007;
  else
    return (((((r) % 1000000007) * ((r) % 1000000007)) % 1000000007) *
            ((a) % 1000000007)) %
           1000000007;
}
long long int max(long long int a, long long int b) {
  if (a > b)
    return a;
  else
    return b;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  long long int a[n + 3];
  map<long long int, long long int> m;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  while (k) {
    if (k > 0) {
      auto it_begin = m.begin();
      auto it_last = m.end();
      it_last--;
      map<long long int, long long int>::iterator temp;
      if (it_begin->second > it_last->second) {
        temp = it_last;
        temp--;
        long long int sub;
        sub = abs(temp->first - it_last->first);
        if (sub * (it_last->second) <= k) {
          k -= sub * (it_last->second);
          m[temp->first] += it_last->second;
          m.erase(it_last);
        } else {
          long long int s;
          s = k / (it_last->second);
          k = 0;
          if (s > 0) {
            m[it_last->first - s] += it_last->second;
            m.erase(it_last);
          }
        }
      } else {
        temp = it_begin;
        temp++;
        long long int add = abs(temp->first - it_begin->first);
        if (add * (it_begin->second) <= k) {
          k -= add * (it_begin->second);
          m[temp->first] += it_begin->second;
          m.erase(it_begin);
        } else {
          long long int s;
          s = k / (it_begin->second);
          k = 0;
          if (s > 0) {
            long long int x = it_begin->first + s;
            m[x] += it_begin->second;
            m.erase(it_begin);
          }
        }
      }
    } else {
      break;
    }
  }
  auto it = m.begin();
  long long int minx = it->first;
  it = m.end();
  it--;
  long long int manx = it->first;
  cout << manx - minx << endl;
}
