#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)
#define endl '\n'
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define mp make_pair
#define nd second
#define st first
#define type(x) __typeof(x.begin())
typedef pair < int ,int > pii;
typedef long long ll;
const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 5e5 + 5;
int n, k, C[N];
void doit() {
sort(C + 1, C + n + 1);
int last = C[1], temp = k;
FOR(i, 2, n) {
if((C[i] - last) * (ll) (i - 1) <= k) {
k -= (C[i] - last) * (i - 1);
last = C[i];
}
}
int j = 0; while(j + 1 <= n && C[j + 1] <= last) j++;
int go = k / j, left = k % j;
FOR(i, 1, j) C[i] = last + go + (i <= left);
k = temp;
}
void rev() { FOR(i, 1, n) C[i] = -C[i]; }
int main() {
scanf("%d %d", &n, &k);
FOR(i, 1, n)
scanf("%d", &C[i]);
doit(); rev();
doit(); rev();
sort(C + 1, C + n + 1);
printf("%d\n", C[n] - C[1]);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBvcnRhIChiYXMgKyBzb24gPj4gMSkKI2RlZmluZSBzYWcgKGsgKyBrICsgMSkKI2RlZmluZSBzb2wgKGsgKyBrKQojZGVmaW5lIGVuZGwgJ1xuJwojZGVmaW5lIGZvcmVhY2goaSx4KSBmb3IodHlwZSh4KWk9eC5iZWdpbigpO2khPXguZW5kKCk7aSsrKQojZGVmaW5lIEZPUihpaSxhYSxiYikgZm9yKGludCBpaT1hYTtpaTw9YmI7aWkrKykKI2RlZmluZSBST0YoaWksYWEsYmIpIGZvcihpbnQgaWk9YWE7a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