#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	MAX = 5e5;

int			w[MAX];
int			N, k;

bool	ok_min(int min)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] < min)
			cnt += min-w[i];
	return cnt <= k;
}

bool	ok_max(int max)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] > max)
			cnt += w[i] - max;
	return cnt <= k;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0);
	std::cin >> N >> k;

	ll	tot = 0;
	for (int i(0); i < N; ++i)
	{
		std::cin >> w[i];
		tot += w[1];
	}

	int	left(0), right(1e9);

	while (left +1< right)
	{
		int	mid = (left + right) / 2;
		if (ok_min(mid))
			left = mid;
		else
			right = mid - 1;
	}

	int	min_bound = (ok_min(right) ? right : left);

	int	left2(0), right2(1e9);
	while (left2 +1< right2)
	{
		int	mid = (left2+right2)/2;
		if (ok_max(mid))
			right2 = mid;
		else
			left2 = mid+1;
	}

	int	max_bound = (ok_max(left2) ? left2 : right2);
	if (min_bound > max_bound)
		pnl(tot%2);
	else
		pnl(max_bound - min_bound);

}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	MAX = 5e5;

int			w[MAX];
int			N, k;

bool	ok_min(int min)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] < min)
			cnt += min-w[i];
	return cnt <= k;
}

bool	ok_max(int max)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] > max)
			cnt += w[i] - max;
	return cnt <= k;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0);
	std::cin >> N >> k;

	ll	tot = 0;
	for (int i(0); i < N; ++i)
	{
		std::cin >> w[i];
		tot += w[i];
	}

	int	left(0), right(1e9);

	while (left +1< right)
	{
		int	mid = (left + right) / 2;
		if (ok_min(mid))
			left = mid;
		else
			right = mid;
	}

	int	min_bound = left;

	int	left2(0), right2(1e9);
	while (left2 +1< right2)
	{
		int	mid = (left2+right2)/2;
		if (ok_max(mid))
			right2 = mid;
		else
			left2 = mid;
	}

	int	max_bound = left2+1;

	if (min_bound > max_bound)
		pnl(tot%2);
	else
		pnl(max_bound - min_bound);

}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	MAX = 5e5;

int			w[MAX];
int			N, k;

bool	ok_min(int min)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] < min)
			cnt += min-w[i];
	return cnt <= k;
}

bool	ok_max(int max)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] > max)
			cnt += w[i] - max;
	return cnt <= k;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0);
	std::cin >> N >> k;

	int	min=1e9, max=0;

	for (int i(0); i < N; ++i)
	{
		std::cin >> w[i];
		min = std::min(min,w[i]);
		max = std::max(max, w[i]);
	}

	int	left(min), right(max);

	while (left < right)
	{
		int	mid = (1+left + right) / 2;
		if (ok_min(mid))
			left = mid;
		else
			right = mid - 1;
	}

	int	left2(min), right2(max);
	while (left2 < right2)
	{
		int	mid = (1+left2+right2)/2;
		if (ok_max(mid))
			right2 = mid;
		else
			left2 = mid+1;
	}

	pnl(left2-left);

}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	MAX = 5e5;

int			w[MAX];
int			N, k;

bool	ok_min(int min)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] < min)
			cnt += min-w[i];
	return cnt <= k;
}

bool	ok_max(int max)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] > max)
			cnt += w[i] - max;
	return cnt <= k;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0);
	std::cin >> N >> k;

	ll	tot = 0;
	for (int i(0); i < N; ++i)
	{
		std::cin >> w[i];
		tot += w[i];
	}

	int	left(0), right(1e9);

	while (left +1< right)
	{
		int	mid = (left + right) / 2;
		if (ok_min(mid))
			left = mid;
		else
			right = mid;
	}

	int	min_bound = left;

	int	left2(0), right2(1e9);
	while (left2 +1< right2)
	{
		int	mid = (left2+right2)/2;
		if (ok_max(mid))
			right2 = mid;
		else
			left2 = mid;
	}

	int	max_bound = left2+1;

	if (min_bound > max_bound)
		pnl(!!(tot%N));
	else
		pnl(max_bound - min_bound);

}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	MAX = 5e5;

int			w[MAX];
int			N, k;

bool	ok_min(int min)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] < min)
			cnt += min-w[i];
	return cnt <= k;
}

bool	ok_max(int max)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] > max)
			cnt += w[i] - max;
	return cnt <= k;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0);
	std::cin >> N >> k;

	ll	tot = 0;
	for (int i(0); i < N; ++i)
	{
		std::cin >> w[i];
		tot += w[i];
	}

	int	left(0), right(1e9);

	while (left +1< right)
	{
		int	mid = (left + right) / 2;
		if (ok_min(mid))
			left = mid;
		else
			right = mid;
	}

	int	min_bound = left+1;

	int	left2(0), right2(1e9);
	while (left2 +1< right2)
	{
		int	mid = (left2+right2)/2;
		if (ok_max(mid))
			right2 = mid;
		else
			left2 = mid;
	}

	int	max_bound = left2;
	if (min_bound > max_bound)
		pnl(tot%2);
	else
		pnl(max_bound - min_bound);

}


#include <bits/stdc++.h>

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	MAX = 5e5;

int			w[MAX];
int			N, k;

bool	ok_min(int min)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] < min)
			cnt += min-w[i];
	return cnt <= k;
}

bool	ok_max(int max)
{
	ll	cnt(0);
	for (int i(0); i < N; ++i)
		if (w[i] > max)
			cnt += w[i] - max;
	return cnt <= k;
}

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0);
	std::cin >> N >> k;

	ll	tot = 0;
	for (int i(0); i < N; ++i)
	{
		std::cin >> w[i];
		tot += w[i];
	}

	int	left(0), right(1e9);

	while (left +1< right)
	{
		int	mid = (left + right) / 2;
		if (ok_min(mid))
			left = mid;
		else
			right = mid;
	}

	int	min_bound = left;

	int	left2(0), right2(1e9);
	while (left2 +1< right2)
	{
		int	mid = (left2+right2)/2;
		if (ok_max(mid))
			right2 = mid;
		else
			left2 = mid;
	}

	int	max_bound = left2+1;

	if (min_bound > max_bound-2)
		pnl(!!(tot%N));
	else
		pnl(max_bound - min_bound);

}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#define int num
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=-10,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)/2;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=-10,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)/2;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int sum=0;
int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum%=n;
    }
    sort(A,A+n);
    printf("%d\n",max(sum,min(A[n-1],BS_max())-max(A[0],BS_min())));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#define int num
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=-10,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)/2;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=-10,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)/2;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int sum=0;
int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum%=2;
    }
    sort(A,A+n);
    printf("%d\n",max(sum,min(A[n-1],BS_max())-max(A[0],BS_min())));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#define int num
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=-10,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)/2;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=-10,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)/2;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int sum=0;
int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum%=n;
    }
    sort(A,A+n);
    printf("%d\n",max(sum!=0,min(A[n-1],BS_max())-max(A[0],BS_min())));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=0,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=0,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)>>1;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
    }
    printf("%d\n",max(0,BS_max()-BS_min()));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=-10,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=-10,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)>>1;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int sum=0;
int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum&=1;
    }
    sort(A,A+n);
    printf("%d\n",max(sum,min(A[n-1],BS_max())-max(A[0],BS_min())));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=0,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=0,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)>>1;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}
int sum=0;

int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum&=1;
    }
    sort(A,A+n);
    printf("%d\n",max(sum,BS_max()-BS_min()));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#define int num
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=-10,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)/2;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=-10,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)/2;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int sum=0;
int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum%=n;
    }
    sort(A,A+n);
    printf("%d\n",max(int(sum>0),min(A[n-1],BS_max())-max(A[0],BS_min())));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#define int num
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=-10,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=-10,int r=inf){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)>>1;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int sum=0;
int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
	sum+=A[i];
	sum&=1;
    }
    sort(A,A+n);
    printf("%d\n",max(sum,min(A[n-1],BS_max())-max(A[0],BS_min())));
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e6+10,inf=1e9+10;

int n,k,A[maxn];

bool check_min(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]<x){
	    ans+=x-A[i];
	    if(ans>k) return 1;
	}
    }
    return 0;
}
int BS_min(int l=0,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check_min(mid)){
	return BS_min(l,mid);
    }else{
	return BS_min(mid,r);
    }
}

bool check_max(int x){
    int ans=0;
    rep(i,0,n){
	if(A[i]>x){
	    ans+=A[i]-x;
	    if(ans>=k) return 1;
	}
    }
    return 0;
}
int BS_max(int l=0,int r=inf){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check_max(mid)){
	return BS_max(mid,r);
    }else{
	return BS_max(l,mid);
    }
}

int32_t main(){
    scanf("%d%d",&n,&k);
    rep(i,0,n){
	scanf("%d",A+i);
    }
    sort(A,A+n);
    printf("%d\n",max(0,BS_max()-BS_min()));
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; -- i) b[i] = b[i + 1] + a[i];
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k){
          if (b[i + 1] - 1ll * (n - i) * a[i] < kk) break;
          lval = a[i];
        }else{
          int l = 0, r = k / (i - 1) + 1;
          while (l < r - 1){
            int m = (l + r) >> 1;
            int pos = lower_bound(a + 1, a + n + 1, lval + m) - a;
            if (b[pos] - 1ll * (n - pos + 1) * (lval + m) < kk) r = m;
            else
              l = m;
          }
          lval = lval + l;
        }
        break;
      }
      k -= t;
      if (b[i + 1] - 1ll * (n - i) * a[i] < kk - k){
        int l = 0, r = a[i] - lval + 1;
        while (l < r - 1){
          int m = (l + r) >> 1;
          int pos = lower_bound(a + 1, a + n + 1, lval + m) - a;
          if (b[pos] - 1ll * (n - pos + 1) * (lval + m) < kk - k) r = m;
          else
            l = m;
        }
        lval = lval + l;
        break;
      }
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  //assert(rval >= lval);
  printf("%I64d\n", abs(rval - lval));
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; -- i) b[i] = b[i + 1] + a[i];
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k){
          if (b[i + 1] - 1ll * (n - i) * a[i] < kk) break;
          lval = a[i];
        }else{
          int l = 0, r = k / (i - 1) + 1;
          while (l < r - 1){
            int m = (l + r) >> 1;
            int pos = lower_bound(a + 1, a + n + 1, lval + m) - a;
            if (b[pos] - 1ll * (n - pos + 1) * (lval + m) < kk) r = m;
            else
              l = m;
          }
          lval = lval + l;
        }
        break;
      }
      k -= t;
      if (b[i + 1] - 1ll * (n - i) * a[i] < kk - k) break;
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  printf("%I64d\n", rval - lval);
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++ i) b[i] = b[i - 1] + a[i];
  ll mid = b[n] / n;
  ll tx = 0;
  for (int i = 1; i <= n; ++ i){
    if (a[i] <= mid) tx += mid - a[i];
  }
  if (k >= tx){
    if (b[n] % n) printf("1\n");
    else
      printf("0\n");
  }else{
    ll lval = a[1], rval = a[n], kk = k;
    for (int i = 2; i <= n; ++ i){
      if (a[i] != a[i - 1]){
        ll t = 1ll * (a[i] - a[i - 1]) * (i - 1);
        if (k < t){
          lval += k / (i - 1);
          break;
        }
        k -= t;
        lval = a[i];
      }
    }
    k = kk;
    for (int i = n - 1; i >= 1; -- i){
      if (a[i] != a[i + 1]){
        ll t = 1ll * (a[i + 1] - a[i]) * (n - i);
        if (k < t){
          rval -= k / (n - i);
          break;
        }
        k -= t;
        rval = a[i];
      }
    }
    printf("%d\n", (int)(rval - lval));
  }
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; -- i) b[i] = b[i + 1] + a[i];
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k){
          if (b[i + 1] - 1ll * (n - i) * a[i] < kk) break;
          lval = a[i];
        }else{
          int l = 0, r = k / (i - 1) + 1;
          while (l < r - 1){
            int m = (l + r) >> 1;
            int pos = lower_bound(a + 1, a + n + 1, lval + m) - a;
            if (b[pos] - 1ll * (n - pos + 1) * (lval + m) < kk) r = m;
            else
              l = m;
          }
          lval = lval + l;
        }
        break;
      }
      k -= t;
      if (b[i + 1] - 1ll * (n - i) * a[i] < kk - k){
        int l = 0, r = a[i] - lval + 1;
        while (l < r - 1){
          int m = (l + r) >> 1;
          int pos = lower_bound(a + 1, a + n + 1, lval + m) - a;
          if (b[pos] - 1ll * (n - pos + 1) * (lval + m) < kk - k) r = m;
          else
            l = m;
        }
        lval = lval + l;
        break;
      }
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  assert(rval >= lval);
  printf("%I64d\n", rval - lval);
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k) lval = a[i];
        else
          lval += k / (i - 1);
        break;
      }
      k -= t;
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  printf("%I64d\n", rval - lval);
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; -- i) b[i] = b[i + 1] + a[i];
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k){
          if (b[i + 1] - 1ll * (n - i) * a[i] < kk) break;
          lval = a[i];
        }else{
          ll tmp = lval;
          lval += k / (i - 1);
          int pos = lower_bound(a + 1, a + n + 1, lval) - a;
          if (b[pos] - 1ll * (n - pos + 1) * lval < kk) lval = tmp;
        }
        break;
      }
      k -= t;
      if (b[i + 1] - 1ll * (n - i) * a[i] < kk - k) break;
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  printf("%I64d\n", abs(rval - lval));
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++ i) b[i] = b[i - 1] + a[i];
  ll mid = b[n] / n;
  ll mod = b[n] % n;
  ll tx = 0;
  for (int i = 1; i <= n; ++ i){
    if (i == n - mod + 1) mid ++;
    if (a[i] <= mid) tx += mid - a[i];
  }
  if (k >= tx){
    if (b[n] % n) printf("1\n");
    else
      printf("0\n");
  }else{
    ll lval = a[1], rval = a[n], kk = k;
    for (int i = 2; i <= n; ++ i){
      if (a[i] != a[i - 1]){
        ll t = 1ll * (a[i] - a[i - 1]) * (i - 1);
        if (k < t){
          lval += k / (i - 1);
          break;
        }
        k -= t;
        lval = a[i];
      }
    }
    k = kk;
    for (int i = n - 1; i >= 1; -- i){
      if (a[i] != a[i + 1]){
        ll t = 1ll * (a[i + 1] - a[i]) * (n - i);
        if (k < t){
          rval -= k / (n - i);
          break;
        }
        k -= t;
        rval = a[i];
      }
    }
    printf("%d\n", (int)(rval - lval));
  }
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; -- i) b[i] = b[i + 1] + a[i];
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k){
          if (b[i + 1] - 1ll * (n - i) * a[i] < kk) break;
          lval = a[i];
        }else{
          ll tmp = lval;
          lval += k / (i - 1);
          int l = 0, r = k / (i - 1) + 1;
          while (l < r - 1){
            int m = (l + r) >> 1;
            int pos = lower_bound(a + 1, a + n + 1, lval + m) - a;
            if (b[pos] - 1ll * (n - pos + 1) * (lval + m) < kk) r = m;
            else
              l = m;
          }
          lval = lval + l;
        }
        break;
      }
      k -= t;
      if (b[i + 1] - 1ll * (n - i) * a[i] < kk - k) break;
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  printf("%I64d\n", rval - lval);
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 501000;
int a[N],n,k;
ll b[N];
int main(){
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = n; i >= 1; -- i) b[i] = b[i + 1] + a[i];
  ll lval = a[1], lx = 1, rval = a[n], rx = n;
  ll lm = 0, rm = 0;
  ll left = 0;
  ll kk = k;
  for (int i = 2; i <= n; ++ i){
    if (a[i] != a[i - 1]){
      ll t = 1ll * (a[i] - lval) * (i - 1);
      if (t >= k){
        if (t == k){
          if (b[i + 1] - 1ll * (n - i) * a[i] < kk) break;
          lval = a[i];
        }else{
          ll tmp = lval;
          lval += k / (i - 1);
          int pos = lower_bound(a + 1, a + n + 1, lval) - a;
          if (b[pos] - 1ll * (n - pos + 1) * lval < kk) lval = tmp;
        }
        break;
      }
      k -= t;
      if (b[i + 1] - 1ll * (n - i) * a[i] < kk - k) break;
      lval = a[i];
    }
  }
  k = kk;
  for (int i = n - 1; i >= 1; -- i){
    if (a[i] != a[i + 1]){
      ll t = 1ll * (rval - a[i]) * (n - i);
      if (t >= k){
        if (t == k) rval = a[i];
        else
          rval -= k / (n - i);
        break;
      }
      k -= t;
      rval = a[i];
    }
  }
  printf("%I64d\n", rval - lval);
}


#include<bits/stdc++.h>

using namespace std;
#define int long long
int N, K, a[500009];
long long s[500009];

bool ok1 (int X)
{
    int p = 1, u = N, mij, ras = 0;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] <= X) ras = mij, p = mij + 1;
        else u = mij - 1;
    }
    return (1LL * X * ras - s[ras] <= K);
}

bool ok2 (int Y)
{
    int p = 1, u = N, mij, ras = N + 1;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] >= Y) ras = mij, u = mij - 1;
        else p = mij + 1;
    }
    return (s[N] - s[ras - 1] - 1LL * Y * (N - ras + 1) <= K);
}
#undef int
int main()
{
    #define int long long
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%lld %lld", &N, &K);
for (int i=1; i<=N; i++)
    scanf ("%lld", &a[i]);
sort (a + 1, a + N + 1);
for (int i=1; i<=N; i++)
    s[i] = s[i - 1] + a[i];
int p = 0, u = 2e9, mij, X, Y;
while (p <= u)
{
    mij = p + (u - p) / 2;
    if (ok1 (mij)) X = mij, p = mij + 1;
    else u = mij - 1;
}
p = 0, u = 2e9;
while (p <= u)
{
    mij = p + (u - p) / 2;
    if (ok2 (mij)) Y = mij, u = mij - 1;
    else p = mij + 1;
}
//printf ("%d %d\n", X, Y);
if (X <= Y) printf ("%lld\n", Y - X);
else
if (s[N] % N == 0) printf ("0\n");
else printf ("1\n");
return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define left jhghajkhja
#define right oauighgajk
#define prev aioghajga
#define next ioyhjhfajasj
#define y0 iuadoghasdgj
#define y1 taklahgjkla
#define remainder pogjuakllhga
#define pow pajklgaklha
#define pow10 iopuioadjlgkah
#define div aljghajkghak
#define distance gkuftgjasgfjh
#define uppercase ifyhasjkhakjfas
#define count sajhfkajfa

//#define floor hjakjhaja
//#define time ashjlahjka
//#define double_t double
//#define tm kahjflahaajk

using namespace std;

const int N = 1<<19;

int n,k;
int a[N];
pair < long long, long long > tmp[N],arr[N];
int sz;
long long curr,down,up;
int cnt;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("test.txt","r",stdin);
	//freopen("IN.c_str()","r",stdin);
	//freopen("OUT.c_str()","w",stdin);
	int i;

	scanf("%d %d", &n, &k);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);
	sort(a+1,a+1+n);
	cnt=1;
	for(i=2;i<=n;i++) {
		if(a[i]==a[i-1]) ++cnt;
		else {
			arr[++sz]=make_pair(a[i-1],cnt);
			cnt=1;
		}
	}
	arr[++sz]=make_pair(a[n],cnt);
	arr[++sz]=make_pair(1000000007,1);
	//for(i=1;i<=sz;i++) {
	//	printf("%lld %lld\n", arr[i].first, arr[i].second);
	//}
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i].first-tmp[i-1].first)<=curr) curr-=tmp[i-1].second*(tmp[i].first-tmp[i-1].first),tmp[i].second+=tmp[i-1].second;
		else {
			//printf("i = %d\n", i);
			down=tmp[i-1].first+curr/tmp[i-1].second;
			break;
		}
	}
	//printf("%lld\n", down);
	--sz;
	reverse(arr+1,arr+1+sz);
	arr[++sz]=make_pair(-1000000007,1);
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i-1].first-tmp[i].first)<=curr) curr-=tmp[i-1].second*(tmp[i-1].first-tmp[i].first),tmp[i].second+=tmp[i-1].second;
		else {
			up=tmp[i-1].first-curr/tmp[i-1].second;
			break;
		}
	}
	printf("%lld\n", max(0ll,up-down));

	//fprintf(stderr, "Time: %d ms\n", (int)(clock()*1000.0/CLOCKS_PER_SEC));

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int N, K, a[500009];
long long s[500009];

bool ok1 (int X)
{
    int p = 1, u = N, mij, ras = 0;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] <= X) ras = mij, p = mij + 1;
        else u = mij - 1;
    }
    return (1LL * X * ras - s[ras] <= K);
}

bool ok2 (int Y)
{
    int p = 1, u = N, mij, ras = N + 1;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] >= Y) ras = mij, u = mij - 1;
        else p = mij + 1;
    }
    return (s[N] - s[ras - 1] - 1LL * Y * (N - ras + 1) <= K);
}

int main()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &K);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
sort (a + 1, a + N + 1);
for (int i=1; i<=N; i++)
    s[i] = s[i - 1] + a[i];
int p = 0, u = 2e9, mij, X, Y;
while (p <= u)
{
    mij = p + (u - p) / 2;
    if (ok1 (mij)) X = mij, p = mij + 1;
    else u = mij - 1;
}
p = 0, u = 2e9;
while (p <= u)
{
    mij = p + (u - p) / 2;
    if (ok2 (mij)) Y = mij, u = mij - 1;
    else p = mij + 1;
}
//printf ("%d %d\n", X, Y);
if (X <= Y) printf ("%d\n", Y - X);
else
if (s[N] % N == 0) printf ("0\n");
else printf ("1\n");
return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define left jhghajkhja
#define right oauighgajk
#define prev aioghajga
#define next ioyhjhfajasj
#define y0 iuadoghasdgj
#define y1 taklahgjkla
#define remainder pogjuakllhga
#define pow pajklgaklha
#define pow10 iopuioadjlgkah
#define div aljghajkghak
#define distance gkuftgjasgfjh
#define uppercase ifyhasjkhakjfas
#define count sajhfkajfa

//#define floor hjakjhaja
//#define time ashjlahjka
//#define double_t double
//#define tm kahjflahaajk

using namespace std;

const int N = 1<<19;

int n,k;
int a[N];
pair < long long, long long > tmp[N],arr[N];
int sz;
long long curr,down,up;
int cnt;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("test.txt","r",stdin);
	//freopen("IN.c_str()","r",stdin);
	//freopen("OUT.c_str()","w",stdin);
	int i;

	scanf("%d %d", &n, &k);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);
	sort(a+1,a+1+n);
	cnt=1;
	for(i=2;i<=n;i++) {
		if(a[i]==a[i-1]) ++cnt;
		else {
			arr[++sz]=make_pair(a[i-1],cnt);
			cnt=1;
		}
	}
	arr[++sz]=make_pair(a[n],cnt);
	arr[++sz]=make_pair(2000000007,1);
	//for(i=1;i<=sz;i++) {
	//	printf("%lld %lld\n", arr[i].first, arr[i].second);
	//}
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i].first-tmp[i-1].first)<=curr) curr-=tmp[i-1].second*(tmp[i].first-tmp[i-1].first),tmp[i].second+=tmp[i-1].second;
		else {
			//printf("i = %d\n", i);
			down=tmp[i-1].first+curr/tmp[i-1].second;
			break;
		}
	}
	//printf("%lld\n", down);
	--sz;
	reverse(arr+1,arr+1+sz);
	arr[++sz]=make_pair(-2000000007,1);
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i-1].first-tmp[i].first)<=curr) curr-=tmp[i-1].second*(tmp[i-1].first-tmp[i].first),tmp[i].second+=tmp[i-1].second;
		else {
			up=tmp[i-1].first-curr/tmp[i-1].second;
			break;
		}
	}
	printf("%lld\n", max(0ll,up-down));

	//fprintf(stderr, "Time: %d ms\n", (int)(clock()*1000.0/CLOCKS_PER_SEC));

	return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define left jhghajkhja
#define right oauighgajk
#define prev aioghajga
#define next ioyhjhfajasj
#define y0 iuadoghasdgj
#define y1 taklahgjkla
#define remainder pogjuakllhga
#define pow pajklgaklha
#define pow10 iopuioadjlgkah
#define div aljghajkghak
#define distance gkuftgjasgfjh
#define uppercase ifyhasjkhakjfas
#define count sajhfkajfa

//#define floor hjakjhaja
//#define time ashjlahjka
//#define double_t double
//#define tm kahjflahaajk

using namespace std;

const int N = 1<<19;

int n,k;
int a[N];
pair < long long, long long > tmp[N],arr[N];
int sz;
long long curr,down,up;
int cnt;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("test.txt","r",stdin);
	//freopen("IN.c_str()","r",stdin);
	//freopen("OUT.c_str()","w",stdin);
	int i;

	scanf("%d %d", &n, &k);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);
	sort(a+1,a+1+n);
	cnt=1;
	for(i=2;i<=n;i++) {
		if(a[i]==a[i-1]) ++cnt;
		else {
			arr[++sz]=make_pair(a[i-1],cnt);
			cnt=1;
		}
	}
	arr[++sz]=make_pair(a[n],cnt);
	arr[++sz]=make_pair(1000000007,1);
	//for(i=1;i<=sz;i++) {
	//	printf("%lld %lld\n", arr[i].first, arr[i].second);
	//}
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i].first-tmp[i-1].first)<=curr && i<sz) curr-=tmp[i-1].second*(tmp[i].first-tmp[i-1].first),tmp[i].second+=tmp[i-1].second;
		else {
			//printf("i = %d\n", i);
			down=tmp[i-1].first+curr/tmp[i-1].second;
			break;
		}
	}
	//printf("%lld\n", down);
	--sz;
	reverse(arr+1,arr+1+sz);
	arr[++sz]=make_pair(-1000000007,1);
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i-1].first-tmp[i].first)<=curr && i<sz) curr-=tmp[i-1].second*(tmp[i-1].first-tmp[i].first),tmp[i].second+=tmp[i-1].second;
		else {
			up=tmp[i-1].first-curr/tmp[i-1].second;
			break;
		}
	}
	printf("%lld\n", max(0ll,up-down));

	//fprintf(stderr, "Time: %d ms\n", (int)(clock()*1000.0/CLOCKS_PER_SEC));

	return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define left jhghajkhja
#define right oauighgajk
#define prev aioghajga
#define next ioyhjhfajasj
#define y0 iuadoghasdgj
#define y1 taklahgjkla
#define remainder pogjuakllhga
#define pow pajklgaklha
#define pow10 iopuioadjlgkah
#define div aljghajkghak
#define distance gkuftgjasgfjh
#define uppercase ifyhasjkhakjfas
#define count sajhfkajfa

//#define floor hjakjhaja
//#define time ashjlahjka
//#define double_t double
//#define tm kahjflahaajk

using namespace std;

const int N = 1<<19;

int n,k;
int a[N];
pair < long long, long long > tmp[N],arr[N];
int sz;
long long curr,down,up;
int cnt;
long long sum;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("test.txt","r",stdin);
	//freopen("IN.c_str()","r",stdin);
	//freopen("OUT.c_str()","w",stdin);
	int i;

	scanf("%d %d", &n, &k);
	for(i=1;i<=n;i++) scanf("%d", &a[i]),sum+=a[i];
	if(n==1) {
		printf("0\n");
		return 0;
	}
	if(sum%n==0) {
		long long ans=0;
		sum/=n;
		for(i=1;i<=n;i++) ans+=abs(sum-a[i]);
		ans/=2;
		if(ans<=(long long)(k)) {
			printf("0\n");
			return 0;
		}
	}
	sort(a+1,a+1+n);
	cnt=1;
	for(i=2;i<=n;i++) {
		if(a[i]==a[i-1]) ++cnt;
		else {
			arr[++sz]=make_pair(a[i-1],cnt);
			cnt=1;
		}
	}
	arr[++sz]=make_pair(a[n],cnt);
	arr[++sz]=make_pair(2000000007,1);
	down=numeric_limits < long long >::min();
	up=numeric_limits < long long >::max();
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i].first-tmp[i-1].first)<=curr) curr-=tmp[i-1].second*(tmp[i].first-tmp[i-1].first),tmp[i].second+=tmp[i-1].second;
		else {
			down=tmp[i-1].first+curr/tmp[i-1].second;
			break;
		}
	}
	--sz;
	reverse(arr+1,arr+1+sz);
	arr[++sz]=make_pair(-2000000007,1);
	curr=k;
	for(i=1;i<=sz;i++) tmp[i]=arr[i];
	for(i=2;i<=sz;i++) {
		if(tmp[i-1].second*(tmp[i-1].first-tmp[i].first)<=curr) curr-=tmp[i-1].second*(tmp[i-1].first-tmp[i].first),tmp[i].second+=tmp[i-1].second;
		else {
			up=tmp[i-1].first-curr/tmp[i-1].second;
			break;
		}
	}
	//printf("%lld %lld\n", down, up);
	printf("%lld\n", max(up-down,1ll));

	//fprintf(stderr, "Time: %d ms\n", (int)(clock()*1000.0/CLOCKS_PER_SEC));

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define int long long
int N, K, a[500009];
long long s[500009];

bool ok1 (int X)
{
    int p = 1, u = N, mij, ras = 0;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] <= X) ras = mij, p = mij + 1;
        else u = mij - 1;
    }
    return (1LL * X * ras - s[ras] <= K);
}

bool ok2 (int Y)
{
    int p = 1, u = N, mij, ras = N + 1;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] >= Y) ras = mij, u = mij - 1;
        else p = mij + 1;
    }
    return (s[N] - s[ras - 1] - 1LL * Y * (N - ras + 1) <= K);
}
#undef int
int main()
{#define int long long
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%lld %lld", &N, &K);
for (int i=1; i<=N; i++)
    scanf ("%lld", &a[i]);
sort (a + 1, a + N + 1);
for (int i=1; i<=N; i++)
    s[i] = s[i - 1] + a[i];
int p = 0, u = 2e9, mij, X, Y;
while (p <= u)
{
    mij = p + (u - p) / 2;
    if (ok1 (mij)) X = mij, p = mij + 1;
    else u = mij - 1;
}
p = 0, u = 2e9;
while (p <= u)
{
    mij = p + (u - p) / 2;
    if (ok2 (mij)) Y = mij, u = mij - 1;
    else p = mij + 1;
}
//printf ("%d %d\n", X, Y);
if (X <= Y) printf ("%lld\n", Y - X);
else
if (s[N] % N == 0) printf ("0\n");
else printf ("1\n");
return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[555555];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k;
	long long tot=0L,max=0L,min=2100600000L;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	else if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=tot/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[555555];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	long long n,k,tot=0,max=0,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	else if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=tot/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[555555];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	long long n,k,tot=0L,max=0L,min=2100600000L;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	else if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=tot/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[500000];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k,tot=0,max=0,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	else if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=tot/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[500000];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k,tot=0,max,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	while(l<=r){
		mid=(l+r)>>1;
		tmp=0L;
		for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
		//cout<<mid<<" "<<tmp<<endl;
		if(tmp<=k)ansmin=mid,l=mid+1;
		else r=mid-1;
	}
	//cout<<ansmin<<endl;
	l=tot/n+1,r=max;
	while(l<=r){
		mid=(l+r)>>1;
		tmp=0L;
		for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
		//cout<<mid<<" "<<tmp<<endl;
		if(tmp<=k)ansmax=mid,r=mid-1;
		else l=mid+1;
	}
	//cout<<ansmax<<endl;
	printf("%d",ansmax-ansmin);
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[500000];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k,tot=0,max,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	else if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=tot/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[555555];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k;
	long long tot=0L,max=0L,min=2100600000L;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	else if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=(tot-1)/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[500000];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k,tot=0,max,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	int l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	while(l<=r){
		mid=(l+r)>>1;
		tmp=0L;
		for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
		//cout<<mid<<" "<<tmp<<endl;
		if(tmp<=k)ansmin=mid,l=mid+1;
		else r=mid-1;
	}
	//cout<<ansmin<<endl;
	l=tot/n+1,r=max;
	while(l<=r){
		mid=(l+r)>>1;
		tmp=0L;
		for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
		//cout<<mid<<" "<<tmp<<endl;
		if(tmp<=k)ansmax=mid,r=mid-1;
		else l=mid+1;
	}
	//cout<<ansmax<<endl;
	printf("%d",ansmax-ansmin);
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[500000];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k,tot=0,max,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	long long l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp=0L;
	if(min==max)printf("0\n");
	if(k==0)printf("%d\n",max-min);
	else{
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmin=mid,l=mid+1;
			else r=mid-1;
		}
		//cout<<ansmin<<endl;
		l=tot/n+1,r=max;
		while(l<=r){
			mid=(l+r)>>1;
			tmp=0L;
			for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
			//cout<<mid<<" "<<tmp<<endl;
			if(tmp<=k)ansmax=mid,r=mid-1;
			else l=mid+1;
		}
		//cout<<ansmax<<endl;
		printf("%d\n",ansmax-ansmin);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int c[500000];
int mmax(int a, int b){
	if(a>b)return a;
	else return b;
}
int mmin(int a, int b){
	if(a<b)return a;
	else return b;
}
int main(void){
	int n,k,tot=0,max,min=2100600000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&c[i]),tot+=c[i],max=mmax(max,c[i]),min=mmin(min,c[i]);
	std::sort(c,c+n);
//	int min=1,max=n-1,tmp;
//	for(int i=1;i<=k;i++){
//		min=1;
//		tmp=c[0]+1;
//		while(tmp>c[min]&&min<n)min++;
//		c[min-1]=tmp;
//		max=n-2;
//		tmp=c[n-1]-1;
//		while(tmp<c[max]&&max>=0)max--;
//		c[max+1]=tmp;
//	}
	int l=min,r=tot/n,mid,ansmin=min,ansmax=max;
	long long tmp;
	while(l<=r){
		mid=(l+r)>>1;
		tmp=0;
		for(int i=0;i<n;i++)if(c[i]<mid)tmp+=mid-c[i];
		//cout<<mid<<" "<<tmp<<endl;
		if(tmp<=k)ansmin=mid,l=mid+1;
		else r=mid-1;
	}
	//cout<<ansmin<<endl;
	l=tot/n+1,r=max;
	while(l<=r){
		mid=(l+r)>>1;
		tmp=0;
		for(int i=0;i<n;i++)if(c[i]>mid)tmp+=c[i]-mid;
		//cout<<mid<<" "<<tmp<<endl;
		if(tmp<=k)ansmax=mid,r=mid-1;
		else l=mid+1;
	}
	//cout<<ansmax<<endl;
	printf("%d",ansmax-ansmin);
	return 0;
}


/*
 * Package: StandardCodeLibrary.Core
 * */
//引进常用的头文件并使用std名字空间;
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

//用于减少代码量的宏;
#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=(b);--i)
#define rrepf(i,a,b) fdt(i,(a)-1,b)
#define rep(i,n) repf(i,0,n)
#define rrep(i,n) rrepf(i,n,0)
#define for_each(e,s) for (__typeof__((s).begin()) e=(s).begin();e!=(s).end();++e)
#define for_nonempty_subsets(subset,set) for (int subset=set;subset;subset=(subset-1)&(set))
#define for_in_charset(i,charset) for (cstr i=(charset);*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define sf scanf
#define pf printf
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define lb lower_bound
#define ub upper_bound
#define rnk order_of_key
#define sel find_by_order
#define ctz __builtin_ctz
#define clz __builtin_clz
#define bc __builtin_popcount
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())
#define rev(x) reverse(all(x))
#define shf(x) random_shuffle(all(x))
#define nxtp(x) next_permutation(all(x))

//调试相关的宏;
#ifndef DEBUG
#define prt(x) (cerr)
#define asrtWA(s) do if(!(s))exit(0);whl(0)
#define asrtTLE(s) do if(!(s))whl(1);whl(0)
#define asrtMLE(s) do if(!(s))whl(new int);whl(0)
#define asrtOLE(s) do if(!(s))whl(1)puts("OLE");whl(0)
#define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)
#define runtime() (cerr)
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#else
#define prt(x) cerr<<"Line "<<__LINE__<<": "<<#x" = "<<(x)<<endl
#define asrtWA(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtTLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtMLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtOLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtRE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define runtime() cerr<<"Used: "<<db(clock())/CLOCKS_PER_SEC<<"s"<<endl
#define input(in)
#define output(out)
#endif

//常用数据类型;
typedef long long int lli;
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<lli> vl;
typedef vec<vl> vvl;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<char> vc;
typedef vec<vc> vvc;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef vec<pii> vpii;
typedef vec<pll> vpll;
typedef vec<pdd> vpdd;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;

//常用常量:int的最大值;lli的最大值;db的误差相关常数;欧拉常数;圆周率;移动向量;取模使用的除数;
int oo=(~0u)>>1;
lli ooll=(~0ull)>>1;
db inf=1e+10;
db eps=1e-10;
db gam=0.5772156649015328606;
db pi=acos(-1.0);
int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};
int MOD=1000000007;

//常用函数:最大最小值更新;数学相关函数;输入和输出;树状数组;并查集;可合并堆;
template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
template<typename type>inline type mod(const type& x){rtn x%MOD;}
inline int sgn(const db& x){rtn (x>+eps)-(x<-eps);}
inline int dbcmp(const db& a,const db& b){rtn sgn(a-b);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>inline pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline pr<type,type> operator*(const pr<type,type>& a,const type& b){rtn mp(a.x*b,a.y*b);}
template<typename type>inline pr<type,type> operator/(const pr<type,type>& a,const type& b){rtn mp(a.x/b,a.y/b);}
template<typename type>inline pr<type,type>& operator-=(pr<type,type>& a,const pr<type,type>& b){rtn a=a-b;}
template<typename type>inline pr<type,type>& operator+=(pr<type,type>& a,const pr<type,type>& b){rtn a=a+b;}
template<typename type>inline pr<type,type>& operator*=(pr<type,type>& a,const type& b){rtn a=a*b;}
template<typename type>inline pr<type,type>& operator/=(pr<type,type>& a,const type& b){rtn a=a/b;}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.y-a.y*b.x;}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.x+a.y*b.y;}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
inline lli bin_pow(lli x,lli y){lli z=1;whl(y){if(y&1)z=mod(z*x);x=mod(sqr(x)),y>>=1;}rtn z;}
template<typename istream,typename first_type,typename second_type>inline istream& operator>>(istream& cin,pr<first_type,second_type>& x){rtn cin>>x.x>>x.y;}
template<typename ostream,typename first_type,typename second_type>inline ostream& operator<<(ostream& cout,const pr<first_type,second_type>& x){rtn cout<<x.x<<" "<<x.y;}
template<typename istream,typename type>inline istream& operator>>(istream& cin,vec<type>& x){rep(i,sz(x))cin>>x[i];rtn cin;}
template<typename ostream,typename type>inline ostream& operator<<(ostream& cout,const vec<type>& x){rep(i,sz(x))cout<<x[i]<<(i+1==sz(x)?"":" ");rtn cout;}
inline ostream& pdb(int prcs,db x){rtn cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));rrep(i,y){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
inline void make_set(vpii& st){rep(i,sz(st))st[i]=mp(i,1);}
inline int find_set(vpii& st,int x){int y=x,z;whl(y!=st[y].x)y=st[y].x;whl(x!=st[x].x)z=st[x].x,st[x].x=y,x=z;rtn y;}
inline bool union_set(vpii& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?(st[a].y>st[b].y?st[a].x=b,st[a].y+=st[b].y:st[b].x=a,st[b].y+=st[a].y),true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.ins(*b.begin()),b.ers(b.begin());}

//初始化;
struct Initializer{
#ifndef DEBUG
Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#else
~Initializer(){runtime();}
#endif
}initializer;

//非标准;
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
typedef __gnu_cxx::rope<char> rope;
template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};

int n,k;
bool gao(vi c,int mx,int& ans)
{
	int t=0;
	rep(i,n) if (c[i]>mx) t+=c[i]-mx,c[i]=mx;
	if (t>k) rtn false;
	rep(i,n)
	{
		if (c[i]>mx) rtn false;
		if (i+1==n) rtn true;
		if ((c[i+1]-c[i])*(i+1)<t)
			t-=(c[i+1]-c[i])*(i+1);
		else
		{
			ans=mx-(t/(i+1)+c[i]);
			rtn true;
		}
	}
}

int main()
{
	cin>>n>>k;
	if (n==1) {cout<<0<<endl;rtn 0;}
	vi c(n);
	cin>>c;
	srt(c);
	int l=0,r=1000000000;
	while (l+1!=r)
	{
		int m=(l+r)/2,_;
		if (gao(c,m,_)) r=m;
		else l=m;
	}
	int ans;
	gao(c,r,ans);
	cout<<ans<<endl;
}


/*
 * Package: StandardCodeLibrary.Core
 * */
//引进常用的头文件并使用std名字空间;
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

//用于减少代码量的宏;
#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=(b);--i)
#define rrepf(i,a,b) fdt(i,(a)-1,b)
#define rep(i,n) repf(i,0,n)
#define rrep(i,n) rrepf(i,n,0)
#define for_each(e,s) for (__typeof__((s).begin()) e=(s).begin();e!=(s).end();++e)
#define for_nonempty_subsets(subset,set) for (int subset=set;subset;subset=(subset-1)&(set))
#define for_in_charset(i,charset) for (cstr i=(charset);*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define sf scanf
#define pf printf
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define lb lower_bound
#define ub upper_bound
#define rnk order_of_key
#define sel find_by_order
#define ctz __builtin_ctz
#define clz __builtin_clz
#define bc __builtin_popcount
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())
#define rev(x) reverse(all(x))
#define shf(x) random_shuffle(all(x))
#define nxtp(x) next_permutation(all(x))

//调试相关的宏;
#ifndef DEBUG
#define prt(x) (cerr)
#define asrtWA(s) do if(!(s))exit(0);whl(0)
#define asrtTLE(s) do if(!(s))whl(1);whl(0)
#define asrtMLE(s) do if(!(s))whl(new int);whl(0)
#define asrtOLE(s) do if(!(s))whl(1)puts("OLE");whl(0)
#define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)
#define runtime() (cerr)
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#else
#define prt(x) cerr<<"Line "<<__LINE__<<": "<<#x" = "<<(x)<<endl
#define asrtWA(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtTLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtMLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtOLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtRE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define runtime() cerr<<"Used: "<<db(clock())/CLOCKS_PER_SEC<<"s"<<endl
#define input(in)
#define output(out)
#endif

//常用数据类型;
typedef long long int lli;
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<lli> vl;
typedef vec<vl> vvl;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<char> vc;
typedef vec<vc> vvc;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef vec<pii> vpii;
typedef vec<pll> vpll;
typedef vec<pdd> vpdd;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;

//常用常量:int的最大值;lli的最大值;db的误差相关常数;欧拉常数;圆周率;移动向量;取模使用的除数;
int oo=(~0u)>>1;
lli ooll=(~0ull)>>1;
db inf=1e+10;
db eps=1e-10;
db gam=0.5772156649015328606;
db pi=acos(-1.0);
int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};
int MOD=1000000007;

//常用函数:最大最小值更新;数学相关函数;输入和输出;树状数组;并查集;可合并堆;
template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
template<typename type>inline type mod(const type& x){rtn x%MOD;}
inline int sgn(const db& x){rtn (x>+eps)-(x<-eps);}
inline int dbcmp(const db& a,const db& b){rtn sgn(a-b);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>inline pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline pr<type,type> operator*(const pr<type,type>& a,const type& b){rtn mp(a.x*b,a.y*b);}
template<typename type>inline pr<type,type> operator/(const pr<type,type>& a,const type& b){rtn mp(a.x/b,a.y/b);}
template<typename type>inline pr<type,type>& operator-=(pr<type,type>& a,const pr<type,type>& b){rtn a=a-b;}
template<typename type>inline pr<type,type>& operator+=(pr<type,type>& a,const pr<type,type>& b){rtn a=a+b;}
template<typename type>inline pr<type,type>& operator*=(pr<type,type>& a,const type& b){rtn a=a*b;}
template<typename type>inline pr<type,type>& operator/=(pr<type,type>& a,const type& b){rtn a=a/b;}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.y-a.y*b.x;}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.x+a.y*b.y;}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
inline lli bin_pow(lli x,lli y){lli z=1;whl(y){if(y&1)z=mod(z*x);x=mod(sqr(x)),y>>=1;}rtn z;}
template<typename istream,typename first_type,typename second_type>inline istream& operator>>(istream& cin,pr<first_type,second_type>& x){rtn cin>>x.x>>x.y;}
template<typename ostream,typename first_type,typename second_type>inline ostream& operator<<(ostream& cout,const pr<first_type,second_type>& x){rtn cout<<x.x<<" "<<x.y;}
template<typename istream,typename type>inline istream& operator>>(istream& cin,vec<type>& x){rep(i,sz(x))cin>>x[i];rtn cin;}
template<typename ostream,typename type>inline ostream& operator<<(ostream& cout,const vec<type>& x){rep(i,sz(x))cout<<x[i]<<(i+1==sz(x)?"":" ");rtn cout;}
inline ostream& pdb(int prcs,db x){rtn cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));rrep(i,y){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
inline void make_set(vpii& st){rep(i,sz(st))st[i]=mp(i,1);}
inline int find_set(vpii& st,int x){int y=x,z;whl(y!=st[y].x)y=st[y].x;whl(x!=st[x].x)z=st[x].x,st[x].x=y,x=z;rtn y;}
inline bool union_set(vpii& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?(st[a].y>st[b].y?st[a].x=b,st[a].y+=st[b].y:st[b].x=a,st[b].y+=st[a].y),true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.ins(*b.begin()),b.ers(b.begin());}

//初始化;
struct Initializer{
#ifndef DEBUG
Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#else
~Initializer(){runtime();}
#endif
}initializer;

//非标准;
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
typedef __gnu_cxx::rope<char> rope;
template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};

int n,k;
bool gao(vi& c,int mn)
{
	int t=0,cnt=0;
	rep(i,n) if (c[i]<=mn) t+=mn-c[i],cnt++;
	if (t-(cnt?cnt-1:0)>k) rtn false;
	rep(i,n) if (c[i]>mn) t-=c[i]-mn;
	rtn t<=(cnt?cnt-1:0);
}
bool gao(vi& c,int mx,int mn,int t,int cnt)
{
	int s=0;
	rep(i,n) if (c[i]>mx) s+=c[i]-mx;
	if (s<=t) rtn true;
	else
	{
		if (cnt)
		{
			if (mx>mn&&s<=t+cnt-1&&s<=k) rtn true;
			else rtn false;
		}
		else rtn false;
	}
}
int solve(vi& c,int mn)
{
	int t=0,cnt=0;
	rep(i,n) if (c[i]<=mn) t+=mn-c[i],cnt++;
	int l=mn-1,r=1000000000;
	while (l+1!=r)
	{
		int m=(l+r)/2;
		if (gao(c,m,mn,t,cnt)) r=m;
		else l=m;
	}
	return r-mn;
}

int main()
{
	cin>>n>>k;
	if (n==1) {cout<<0<<endl;rtn 0;}
	vi c(n);
	cin>>c;
	srt(c);
	rev(c);
	int l=1,r=1000000001;
	while (l+1!=r)
	{
		int m=(l+r)/2;
		if (gao(c,m)) l=m;
		else r=m;
	}
	int ans=solve(c,l);
	cout<<ans<<endl;
}


/*
 * Package: StandardCodeLibrary.Core
 * */
//引进常用的头文件并使用std名字空间;
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

//用于减少代码量的宏;
#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=(b);--i)
#define rrepf(i,a,b) fdt(i,(a)-1,b)
#define rep(i,n) repf(i,0,n)
#define rrep(i,n) rrepf(i,n,0)
#define for_each(e,s) for (__typeof__((s).begin()) e=(s).begin();e!=(s).end();++e)
#define for_nonempty_subsets(subset,set) for (int subset=set;subset;subset=(subset-1)&(set))
#define for_in_charset(i,charset) for (cstr i=(charset);*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define sf scanf
#define pf printf
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define lb lower_bound
#define ub upper_bound
#define rnk order_of_key
#define sel find_by_order
#define ctz __builtin_ctz
#define clz __builtin_clz
#define bc __builtin_popcount
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())
#define rev(x) reverse(all(x))
#define shf(x) random_shuffle(all(x))
#define nxtp(x) next_permutation(all(x))

//调试相关的宏;
#ifndef DEBUG
#define prt(x) (cerr)
#define asrtWA(s) do if(!(s))exit(0);whl(0)
#define asrtTLE(s) do if(!(s))whl(1);whl(0)
#define asrtMLE(s) do if(!(s))whl(new int);whl(0)
#define asrtOLE(s) do if(!(s))whl(1)puts("OLE");whl(0)
#define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)
#define runtime() (cerr)
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#else
#define prt(x) cerr<<"Line "<<__LINE__<<": "<<#x" = "<<(x)<<endl
#define asrtWA(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtTLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtMLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtOLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtRE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define runtime() cerr<<"Used: "<<db(clock())/CLOCKS_PER_SEC<<"s"<<endl
#define input(in)
#define output(out)
#endif

//常用数据类型;
typedef long long int lli;
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<lli> vl;
typedef vec<vl> vvl;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<char> vc;
typedef vec<vc> vvc;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef vec<pii> vpii;
typedef vec<pll> vpll;
typedef vec<pdd> vpdd;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;

//常用常量:int的最大值;lli的最大值;db的误差相关常数;欧拉常数;圆周率;移动向量;取模使用的除数;
int oo=(~0u)>>1;
lli ooll=(~0ull)>>1;
db inf=1e+10;
db eps=1e-10;
db gam=0.5772156649015328606;
db pi=acos(-1.0);
int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};
int MOD=1000000007;

//常用函数:最大最小值更新;数学相关函数;输入和输出;树状数组;并查集;可合并堆;
template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
template<typename type>inline type mod(const type& x){rtn x%MOD;}
inline int sgn(const db& x){rtn (x>+eps)-(x<-eps);}
inline int dbcmp(const db& a,const db& b){rtn sgn(a-b);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>inline pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline pr<type,type> operator*(const pr<type,type>& a,const type& b){rtn mp(a.x*b,a.y*b);}
template<typename type>inline pr<type,type> operator/(const pr<type,type>& a,const type& b){rtn mp(a.x/b,a.y/b);}
template<typename type>inline pr<type,type>& operator-=(pr<type,type>& a,const pr<type,type>& b){rtn a=a-b;}
template<typename type>inline pr<type,type>& operator+=(pr<type,type>& a,const pr<type,type>& b){rtn a=a+b;}
template<typename type>inline pr<type,type>& operator*=(pr<type,type>& a,const type& b){rtn a=a*b;}
template<typename type>inline pr<type,type>& operator/=(pr<type,type>& a,const type& b){rtn a=a/b;}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.y-a.y*b.x;}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.x+a.y*b.y;}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
inline lli bin_pow(lli x,lli y){lli z=1;whl(y){if(y&1)z=mod(z*x);x=mod(sqr(x)),y>>=1;}rtn z;}
template<typename istream,typename first_type,typename second_type>inline istream& operator>>(istream& cin,pr<first_type,second_type>& x){rtn cin>>x.x>>x.y;}
template<typename ostream,typename first_type,typename second_type>inline ostream& operator<<(ostream& cout,const pr<first_type,second_type>& x){rtn cout<<x.x<<" "<<x.y;}
template<typename istream,typename type>inline istream& operator>>(istream& cin,vec<type>& x){rep(i,sz(x))cin>>x[i];rtn cin;}
template<typename ostream,typename type>inline ostream& operator<<(ostream& cout,const vec<type>& x){rep(i,sz(x))cout<<x[i]<<(i+1==sz(x)?"":" ");rtn cout;}
inline ostream& pdb(int prcs,db x){rtn cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));rrep(i,y){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
inline void make_set(vpii& st){rep(i,sz(st))st[i]=mp(i,1);}
inline int find_set(vpii& st,int x){int y=x,z;whl(y!=st[y].x)y=st[y].x;whl(x!=st[x].x)z=st[x].x,st[x].x=y,x=z;rtn y;}
inline bool union_set(vpii& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?(st[a].y>st[b].y?st[a].x=b,st[a].y+=st[b].y:st[b].x=a,st[b].y+=st[a].y),true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.ins(*b.begin()),b.ers(b.begin());}

//初始化;
struct Initializer{
#ifndef DEBUG
Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#else
~Initializer(){runtime();}
#endif
}initializer;

//非标准;
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
typedef __gnu_cxx::rope<char> rope;
template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};

int n,k;
bool gao(vi& c,int mn)
{
	int t=0;
	rep(i,n) if (c[i]<mn) t+=mn-c[i];
	if (t>k) rtn false;
	rep(i,n) if (c[i]>mn) t-=c[i]-mn;
	rtn t<=0;
}
bool gao(vi& c,int mx,int mn,int t,int cnt)
{
	int s=0;
	rep(i,n) if (c[i]>mx) s+=c[i]-mx;
	if (s<=t) rtn true;
	else
	{
		if (cnt)
		{
			if (mx>mn&&s<=t+cnt-1&&s<=k) rtn true;
			else rtn false;
		}
		else rtn false;
	}
}
int solve(vi& c,int mn)
{
	int t=0,cnt=0;
	rep(i,n) if (c[i]<=mn) t+=mn-c[i],cnt++;
	int l=mn-1,r=1000000000;
	while (l+1!=r)
	{
		int m=(l+r)/2;
		if (gao(c,m,mn,t,cnt)) r=m;
		else l=m;
	}
	return r-mn;
}

int main()
{
	cin>>n>>k;
	if (n==1) {cout<<0<<endl;rtn 0;}
	vi c(n);
	cin>>c;
	srt(c);
	rev(c);
	int l=1,r=1000000001;
	while (l+1!=r)
	{
		int m=(l+r)/2;
		if (gao(c,m)) l=m;
		else r=m;
	}
	int ans=solve(c,l);
	cout<<ans<<endl;
}


/*
 * Package: StandardCodeLibrary.Core
 * */
//引进常用的头文件并使用std名字空间;
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

//用于减少代码量的宏;
#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=(b);--i)
#define rrepf(i,a,b) fdt(i,(a)-1,b)
#define rep(i,n) repf(i,0,n)
#define rrep(i,n) rrepf(i,n,0)
#define for_each(e,s) for (__typeof__((s).begin()) e=(s).begin();e!=(s).end();++e)
#define for_nonempty_subsets(subset,set) for (int subset=set;subset;subset=(subset-1)&(set))
#define for_in_charset(i,charset) for (cstr i=(charset);*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define sf scanf
#define pf printf
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define lb lower_bound
#define ub upper_bound
#define rnk order_of_key
#define sel find_by_order
#define ctz __builtin_ctz
#define clz __builtin_clz
#define bc __builtin_popcount
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())
#define rev(x) reverse(all(x))
#define shf(x) random_shuffle(all(x))
#define nxtp(x) next_permutation(all(x))

//调试相关的宏;
#ifndef DEBUG
#define prt(x) (cerr)
#define asrtWA(s) do if(!(s))exit(0);whl(0)
#define asrtTLE(s) do if(!(s))whl(1);whl(0)
#define asrtMLE(s) do if(!(s))whl(new int);whl(0)
#define asrtOLE(s) do if(!(s))whl(1)puts("OLE");whl(0)
#define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)
#define runtime() (cerr)
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#else
#define prt(x) cerr<<"Line "<<__LINE__<<": "<<#x" = "<<(x)<<endl
#define asrtWA(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtTLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtMLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtOLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtRE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define runtime() cerr<<"Used: "<<db(clock())/CLOCKS_PER_SEC<<"s"<<endl
#define input(in)
#define output(out)
#endif

//常用数据类型;
typedef long long int lli;
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<lli> vl;
typedef vec<vl> vvl;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<char> vc;
typedef vec<vc> vvc;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef vec<pii> vpii;
typedef vec<pll> vpll;
typedef vec<pdd> vpdd;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;

//常用常量:int的最大值;lli的最大值;db的误差相关常数;欧拉常数;圆周率;移动向量;取模使用的除数;
int oo=(~0u)>>1;
lli ooll=(~0ull)>>1;
db inf=1e+10;
db eps=1e-10;
db gam=0.5772156649015328606;
db pi=acos(-1.0);
int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};
int MOD=1000000007;

//常用函数:最大最小值更新;数学相关函数;输入和输出;树状数组;并查集;可合并堆;
template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
template<typename type>inline type mod(const type& x){rtn x%MOD;}
inline int sgn(const db& x){rtn (x>+eps)-(x<-eps);}
inline int dbcmp(const db& a,const db& b){rtn sgn(a-b);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>inline pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline pr<type,type> operator*(const pr<type,type>& a,const type& b){rtn mp(a.x*b,a.y*b);}
template<typename type>inline pr<type,type> operator/(const pr<type,type>& a,const type& b){rtn mp(a.x/b,a.y/b);}
template<typename type>inline pr<type,type>& operator-=(pr<type,type>& a,const pr<type,type>& b){rtn a=a-b;}
template<typename type>inline pr<type,type>& operator+=(pr<type,type>& a,const pr<type,type>& b){rtn a=a+b;}
template<typename type>inline pr<type,type>& operator*=(pr<type,type>& a,const type& b){rtn a=a*b;}
template<typename type>inline pr<type,type>& operator/=(pr<type,type>& a,const type& b){rtn a=a/b;}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.y-a.y*b.x;}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.x+a.y*b.y;}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
inline lli bin_pow(lli x,lli y){lli z=1;whl(y){if(y&1)z=mod(z*x);x=mod(sqr(x)),y>>=1;}rtn z;}
template<typename istream,typename first_type,typename second_type>inline istream& operator>>(istream& cin,pr<first_type,second_type>& x){rtn cin>>x.x>>x.y;}
template<typename ostream,typename first_type,typename second_type>inline ostream& operator<<(ostream& cout,const pr<first_type,second_type>& x){rtn cout<<x.x<<" "<<x.y;}
template<typename istream,typename type>inline istream& operator>>(istream& cin,vec<type>& x){rep(i,sz(x))cin>>x[i];rtn cin;}
template<typename ostream,typename type>inline ostream& operator<<(ostream& cout,const vec<type>& x){rep(i,sz(x))cout<<x[i]<<(i+1==sz(x)?"":" ");rtn cout;}
inline ostream& pdb(int prcs,db x){rtn cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));rrep(i,y){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
inline void make_set(vpii& st){rep(i,sz(st))st[i]=mp(i,1);}
inline int find_set(vpii& st,int x){int y=x,z;whl(y!=st[y].x)y=st[y].x;whl(x!=st[x].x)z=st[x].x,st[x].x=y,x=z;rtn y;}
inline bool union_set(vpii& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?(st[a].y>st[b].y?st[a].x=b,st[a].y+=st[b].y:st[b].x=a,st[b].y+=st[a].y),true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.ins(*b.begin()),b.ers(b.begin());}

//初始化;
struct Initializer{
#ifndef DEBUG
Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#else
~Initializer(){runtime();}
#endif
}initializer;

//非标准;
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
typedef __gnu_cxx::rope<char> rope;
template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};

long long n,k;
bool gao(vl& c,long long mn)
{
	long long t=0;
	rep(i,n) if (c[i]<mn) t+=mn-c[i];
	if (t>k) rtn false;
	rep(i,n) if (c[i]>mn) t-=c[i]-mn;
	rtn t<=0;
}
bool gao(vl& c,long long mx,long long mn,long long t,long long cnt)
{
	long long s=0;
	rep(i,n) if (c[i]>mx) s+=c[i]-mx;
	if (s<=t) rtn true;
	else
	{
		if (mx>mn&&cnt)
		{
			t+=cnt-1;
			t=min(t,k);//if(mx==3)prt(cnt),prt(s),prt(t);
			rtn s<=t;
		}
		else rtn false;
	}
}
long long solve(vl& c,long long mn)
{
	long long t=0,cnt=0;
	rep(i,n) if (c[i]<=mn) t+=mn-c[i],cnt++;
	long long l=mn-1,r=1000000000;
	while (l+1!=r)
	{
		long long m=(l+r)/2;
		if (gao(c,m,mn,t,cnt)) r=m;
		else l=m;
		prt(mp(l,r));
	}
	prt(r);
	return r-mn;
}
int main()
{
	cin>>n>>k;
	if (n==1) {cout<<0<<endl;rtn 0;}
	vl c(n);
	cin>>c;
	srt(c);
	rev(c);
	long long l=1,r=1000000001;
	while (l+1!=r)
	{
		long long m=(l+r)/2;
		if (gao(c,m)) l=m;
		else r=m;
	}
	prt(l);
	long long ans=solve(c,l);
	cout<<ans<<endl;
}


/*
 * Package: StandardCodeLibrary.Core
 * */
//引进常用的头文件并使用std名字空间;
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

//用于减少代码量的宏;
#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=(b);--i)
#define rrepf(i,a,b) fdt(i,(a)-1,b)
#define rep(i,n) repf(i,0,n)
#define rrep(i,n) rrepf(i,n,0)
#define for_each(e,s) for (__typeof__((s).begin()) e=(s).begin();e!=(s).end();++e)
#define for_nonempty_subsets(subset,set) for (int subset=set;subset;subset=(subset-1)&(set))
#define for_in_charset(i,charset) for (cstr i=(charset);*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define sf scanf
#define pf printf
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define lb lower_bound
#define ub upper_bound
#define rnk order_of_key
#define sel find_by_order
#define ctz __builtin_ctz
#define clz __builtin_clz
#define bc __builtin_popcount
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())
#define rev(x) reverse(all(x))
#define shf(x) random_shuffle(all(x))
#define nxtp(x) next_permutation(all(x))

//调试相关的宏;
#ifndef DEBUG
#define prt(x) (cerr)
#define asrtWA(s) do if(!(s))exit(0);whl(0)
#define asrtTLE(s) do if(!(s))whl(1);whl(0)
#define asrtMLE(s) do if(!(s))whl(new int);whl(0)
#define asrtOLE(s) do if(!(s))whl(1)puts("OLE");whl(0)
#define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)
#define runtime() (cerr)
#define input(in) freopen(in,"r",stdin)
#define output(out) freopen(out,"w",stdout)
#else
#define prt(x) cerr<<"Line "<<__LINE__<<": "<<#x" = "<<(x)<<endl
#define asrtWA(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtTLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtMLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtOLE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define asrtRE(s) do if(!(s))cerr<<"Assertion failed: "#s<<endl;whl(0)
#define runtime() cerr<<"Used: "<<db(clock())/CLOCKS_PER_SEC<<"s"<<endl
#define input(in)
#define output(out)
#endif

//常用数据类型;
typedef long long int lli;
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<lli> vl;
typedef vec<vl> vvl;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<char> vc;
typedef vec<vc> vvc;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef vec<pii> vpii;
typedef vec<pll> vpll;
typedef vec<pdd> vpdd;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;

//常用常量:int的最大值;lli的最大值;db的误差相关常数;欧拉常数;圆周率;移动向量;取模使用的除数;
int oo=(~0u)>>1;
lli ooll=(~0ull)>>1;
db inf=1e+10;
db eps=1e-10;
db gam=0.5772156649015328606;
db pi=acos(-1.0);
int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};
int MOD=1000000007;

//常用函数:最大最小值更新;数学相关函数;输入和输出;树状数组;并查集;可合并堆;
template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
template<typename type>inline type mod(const type& x){rtn x%MOD;}
inline int sgn(const db& x){rtn (x>+eps)-(x<-eps);}
inline int dbcmp(const db& a,const db& b){rtn sgn(a-b);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>inline pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline pr<type,type> operator*(const pr<type,type>& a,const type& b){rtn mp(a.x*b,a.y*b);}
template<typename type>inline pr<type,type> operator/(const pr<type,type>& a,const type& b){rtn mp(a.x/b,a.y/b);}
template<typename type>inline pr<type,type>& operator-=(pr<type,type>& a,const pr<type,type>& b){rtn a=a-b;}
template<typename type>inline pr<type,type>& operator+=(pr<type,type>& a,const pr<type,type>& b){rtn a=a+b;}
template<typename type>inline pr<type,type>& operator*=(pr<type,type>& a,const type& b){rtn a=a*b;}
template<typename type>inline pr<type,type>& operator/=(pr<type,type>& a,const type& b){rtn a=a/b;}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.y-a.y*b.x;}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.x+a.y*b.y;}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
inline lli bin_pow(lli x,lli y){lli z=1;whl(y){if(y&1)z=mod(z*x);x=mod(sqr(x)),y>>=1;}rtn z;}
template<typename istream,typename first_type,typename second_type>inline istream& operator>>(istream& cin,pr<first_type,second_type>& x){rtn cin>>x.x>>x.y;}
template<typename ostream,typename first_type,typename second_type>inline ostream& operator<<(ostream& cout,const pr<first_type,second_type>& x){rtn cout<<x.x<<" "<<x.y;}
template<typename istream,typename type>inline istream& operator>>(istream& cin,vec<type>& x){rep(i,sz(x))cin>>x[i];rtn cin;}
template<typename ostream,typename type>inline ostream& operator<<(ostream& cout,const vec<type>& x){rep(i,sz(x))cout<<x[i]<<(i+1==sz(x)?"":" ");rtn cout;}
inline ostream& pdb(int prcs,db x){rtn cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));rrep(i,y){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
inline void make_set(vpii& st){rep(i,sz(st))st[i]=mp(i,1);}
inline int find_set(vpii& st,int x){int y=x,z;whl(y!=st[y].x)y=st[y].x;whl(x!=st[x].x)z=st[x].x,st[x].x=y,x=z;rtn y;}
inline bool union_set(vpii& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?(st[a].y>st[b].y?st[a].x=b,st[a].y+=st[b].y:st[b].x=a,st[b].y+=st[a].y),true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.ins(*b.begin()),b.ers(b.begin());}

//初始化;
struct Initializer{
#ifndef DEBUG
Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#else
~Initializer(){runtime();}
#endif
}initializer;

//非标准;
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
typedef __gnu_cxx::rope<char> rope;
template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};

int n,k;
bool gao(vi& c,int mn)
{
	int t=0;
	rep(i,n) if (c[i]<mn) t+=mn-c[i];
	if (t>k) rtn false;
	rep(i,n) if (c[i]>mn) t-=c[i]-mn;
	rtn t<=0;
}
bool gao(vi& c,int mx,int mn,int t,int cnt)
{
	int s=0;
	rep(i,n) if (c[i]>mx) s+=c[i]-mx;
	if (s<=t) rtn true;
	else
	{
		if (mx>mn&&cnt)
		{
			t+=cnt-1;
			rtn s<=t;
		}
		else rtn false;
	}
}
int solve(vi& c,int mn)
{
	int t=0,cnt=0;
	rep(i,n) if (c[i]<=mn) t+=mn-c[i],cnt++;
	int l=mn-1,r=1000000000;
	while (l+1!=r)
	{
		int m=(l+r)/2;
		if (gao(c,m,mn,t,cnt)) r=m;
		else l=m;
	}
	return r-mn;
}

int main()
{
	cin>>n>>k;
	if (n==1) {cout<<0<<endl;rtn 0;}
	vi c(n);
	cin>>c;
	srt(c);
	rev(c);
	int l=1,r=1000000001;
	while (l+1!=r)
	{
		int m=(l+r)/2;
		if (gao(c,m)) l=m;
		else r=m;
	}
//	cout<<l<<endl;
	int ans=solve(c,l);
	cout<<ans<<endl;
}