http://codeforces.com/contest/1244/problem/E
#include <bits/stdc++.h>
//#include <queue>
//#include <cmath>
//#include <iostream>
//#include <unordered_map>
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) ((x)&(-x))
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define INF 0x3f3f3f3f
#define ll long long
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int mod=1e9+7;
const int N=1e5+9;
int n;
ll k;
ll a[N];
int main()
{
FAST_IO;
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
ll cnt=1,cntt=1;
ll minn=a[1],maxx=a[n];
ll ans=maxx-minn;
int l=1,r=n;
for(int i=1;i<n;i++)
{
if(i&1)
{
ll d=a[l+1]-a[l];
if(k>=cnt*d) k-=cnt*d,minn=a[l+1];
else
{
minn=a[l]+k/cnt;
k=0;
}
if(k==0)
{
ans=maxx-minn;
break;
}
l++;
cnt++;
}
else
{
ll d=a[r]-a[r-1];
if(k>=cntt*d) k-=cntt*d,maxx=a[r-1];
else
{
maxx=a[r]-k/cntt;
k=0;
}
if(k==0)
{
ans=maxx-minn;
break;
}
r--;
cntt++;
}
}
ans=maxx-minn;
cout<<ans<<endl;
return 0;
}
/*
4 10
1 1 2 2
3 3
7 12 8
*/