#include <bits/stdc++.h>
const int INF_INT = 0x3f3f3f3f;
const long long INF_LL = 0x7f7f7f7f;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1);
using namespace std;
long long n, k;
long long c[500050];
int main(int argc, char const *argv[]) {
  while (scanf("%I64d%I64d", &n, &k) == 2) {
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%I64d", c + i);
      sum += c[i];
    }
    long long L = 0, R = sum / n;
    long long ans1 = 0;
    while (L <= R) {
      long long mid = L + R >> 1;
      long long tmp = 0;
      for (int i = 1; i <= n; i++)
        if (c[i] < mid) tmp += mid - c[i];
      if (tmp <= k)
        ans1 = mid, L = mid + 1;
      else
        R = mid - 1;
    }
    L = (sum + n - 1) / n, R = 1000000000;
    long long ans2 = 0;
    while (L <= R) {
      long long mid = L + R >> 1;
      long long tmp = 0;
      for (int i = 1; i <= n; i++)
        if (c[i] > mid) tmp += c[i] - mid;
      if (tmp <= k)
        ans2 = mid, R = mid - 1;
      else
        L = mid + 1;
    }
    cout << ans2 - ans1 << endl;
  }
  return 0;
}
