#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  while (cin >> n >> k) {
    int a[500005];
    long long mid, a1 = 0, a2 = 0, cnt = 0, L = 0, R = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    sort(a, a + n);
    R = sum / n;
    while (R >= L) {
      mid = (L + R) >> 1;
      cnt = 0;
      for (int i = 0; i < n; i++)
        if (mid > a[i]) cnt += mid - a[i];
      if (cnt <= k)
        a1 = mid, L = mid + 1;
      else
        R = mid - 1;
    }
    L = (sum + n - 1) / n;
    R = 0x3f3f3f3f;
    while (R >= L) {
      mid = (L + R) >> 1;
      cnt = 0;
      for (int i = 0; i < n; i++)
        if (mid < a[i]) cnt += a[i] - mid;
      if (cnt <= k)
        a2 = mid, R = mid - 1;
      else
        L = mid + 1;
    }
    cout << (a2 - a1) << endl;
  }
  return 0;
}
