#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
long long qp(long long a, long long b, long long mod) {
  long long t = 1;
  while (b) {
    if (b & 1) t = t * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return t;
}
struct DOT {
  int x;
  int y;
};
inline void read(int &x) {
  int k = 0;
  char f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  x = k * f;
}
void ex() {
  puts("-1");
  exit(0);
}
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int inf = 0x3f3f3f3f;
const long long Linf = 0x3f3f3f3f3f3f3f3fll;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int maxn = 5e5 + 344;
int n, k;
map<int, int> mp;
int a[maxn], b[maxn];
int main() {
  scanf("%d%d", &n, &k);
  int rembk = k;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    mp[a[i]]++;
  }
  int tot = 0;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) {
      b[++tot] = a[i];
    }
  }
  int mov = 0;
  int mnto = b[1];
  for (int i = 1; i <= tot; i++) {
    if (1ll * mov * (b[i] - b[i - 1]) <= 1ll * k) {
      k -= mov * (b[i] - b[i - 1]);
      mnto = b[i];
      mov += mp[b[i]];
    } else
      break;
  }
  mnto += k / mov;
  k = rembk;
  mov = 0;
  int mxto = b[tot];
  b[tot + 1] = b[tot];
  for (int i = tot; i >= 1; i--) {
    if (1ll * mov * (b[i + 1] - b[i]) <= 1ll * k) {
      k -= mov * (b[i + 1] - b[i]);
      mxto = b[i];
      mov += mp[b[i]];
    } else
      break;
  }
  mxto -= k / mov;
  if (mxto <= mnto) {
    if (sum % n == 0) {
      puts("0");
    } else
      puts("1");
  } else {
    printf("%d\n", mxto - mnto);
  }
}
