#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[500005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (cin >> n >> k) {
    long long sum = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      sum += a[i];
    }
    sort(a + 1, a + 1 + n);
    long long l, r, mid, ans1, ans2;
    l = 0, r = sum / n;
    while (l < r) {
      mid = (l + r + 1) / 2;
      long long p = 0;
      for (int i = 1; i <= n; ++i)
        if (mid > a[i]) p += mid - a[i];
      if (p <= k)
        l = mid;
      else
        r = mid - 1;
    }
    ans1 = l;
    l = sum / n + !(sum % n == 0), r = a[n];
    while (l < r) {
      mid = (l + r) / 2;
      long long p = 0;
      for (int i = 1; i <= n; ++i)
        if (mid < a[i]) p += a[i] - mid;
      if (p <= k)
        r = mid;
      else
        l = mid + 1;
    }
    ans2 = l;
    cout << ans2 - ans1 << endl;
  }
  return 0;
}
