#include <bits/stdc++.h>
using namespace std;
long long int a[500005];
long long total;
int main() {
  int n;
  long long k;
  int k1;
  scanf("%d%d", &n, &k1);
  k = k1;
  total = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k1);
    a[i] = k1;
    total += a[i];
  }
  sort(a + 1, a + n + 1);
  long long int l = a[1], r = a[n];
  int k2 = k;
  long long cnt = 1;
  long long n1 = n;
  int parity = 1;
  if (total % n1 == 0) parity = 0;
  for (int i = 2; i <= n; i++) {
    long long val = 1LL * cnt * (a[i] - l);
    if (val <= k) {
      k -= val;
      cnt++;
      l = a[i];
      continue;
    }
    l += (k / cnt);
    break;
  }
  k = k2;
  cnt = 1;
  for (int i = n - 1; i >= 1; i--) {
    long long val = 1LL * cnt * (r - a[i]);
    if (val <= k) {
      k -= val;
      cnt++;
      r = a[i];
      continue;
    }
    r -= (k / cnt);
    break;
  }
  if (l < r)
    cout << (r - l) << endl;
  else
    cout << parity << endl;
  return 0;
}
