#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
long long c[maxn];
int n;
long long k;
long long cntup(int x) {
  long long cnt = 0;
  for (int i = 0; i < n; ++i)
    if (c[i] > x) cnt += (long long)(c[i] - x);
  return cnt;
}
long long cntdown(int x) {
  long long cnt = 0;
  for (int i = 0; i < n; ++i)
    if (c[i] < x) cnt += (long long)(x - c[i]);
  return cnt;
}
int main() {
  scanf("%d%I64d", &n, &k);
  long long high = 0, low = 0x7fffffff, avg1 = 0, avg2;
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", c + i);
    avg1 += c[i];
    high = max(high, c[i]);
    low = min(low, c[i]);
  }
  avg2 = avg1 / n;
  avg1 = (avg1 + n - 1) / n;
  long long l, r, mid, t1, b1;
  l = avg1, r = high;
  while (l < r + 1) {
    mid = (l + r) >> 1;
    long long ju = cntup(mid);
    if (ju > k) {
      l = mid + 1;
    } else if (ju < k) {
      r = mid - 1;
      t1 = mid;
    } else {
      t1 = mid;
      break;
    }
  }
  l = low, r = avg2;
  while (l < r + 1) {
    mid = (l + r) >> 1;
    long long ju = cntdown(mid);
    if (ju < k) {
      b1 = mid;
      l = mid + 1;
    } else if (ju > k) {
      r = mid - 1;
    } else {
      b1 = mid;
      break;
    }
  }
  printf("%I64d\n", t1 - b1);
  return 0;
}
