//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define int long long

const int MAXN = 2e5 + 10;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n,k,ans,all,tot;
int m[MAXN],c[MAXN];
int cnt[MAXN];
vector<int> v[MAXN];

signed main () {
	ios::sync_with_stdio(false);
	cin >> n >> k;
	all = n;
	for(register int i = 1;i <= n; ++i) {
		cin >> m[i];
		cnt[m[i]]++;
	}
	sort(m + 1,m + n + 1);
	for(register int i = 1;i <= k; ++i)
		cin >> c[i];
	for(register int i = n,at = 1;i >= 1; --i) {
		if(i != n && m[i] != m[i + 1]) at = 1;
		while(v[at].size() >= c[m[i]]) at++;
		v[at].push_back(m[i]);
		tot = max(tot,at);
	}
	cout << tot << endl;
	for(register int i = 1;i <= tot; ++i) {
		int len = v[i].size();
		cout << len << ' ';
		for(register int j = 0;j < len; ++j)
			cout << v[i][j] << ' ';
		cout << endl;
	}
	return 0;
}


//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define int long long

const int MAXN = 2e5 + 10;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n,k,ans,all,tot;
int m[MAXN],c[MAXN];
int cnt[MAXN];
vector<int> v[MAXN];

signed main () {
	ios::sync_with_stdio(false);
	cin >> n >> k;
	all = n;
	for(register int i = 1;i <= n; ++i) {
		cin >> m[i];
		cnt[m[i]]++;
	}
	sort(m + 1,m + n + 1);
	for(register int i = 1;i <= k; ++i)
		cin >> c[i];
	for(register int i = n,at = 1;i >= 1; --i) {
		if((i == n || m[i] != m[i + 1]) && c[m[i]] != c[m[i + 1]]) at = 1;
		while(v[at].size() >= c[m[i]]) at++;
		v[at].push_back(m[i]);
		tot = max(tot,at);
	}
	cout << tot << endl;
	for(register int i = 1;i <= tot; ++i) {
		int len = v[i].size();
		cout << len << ' ';
		for(register int j = 0;j < len; ++j)
			cout << v[i][j] << ' ';
		cout << endl;
	}
	return 0;
}


//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define int long long

const int MAXN = 2e5 + 10;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n,k,ans,tot;
int m[MAXN],c[MAXN];
multiset<int,greater<int> > S;
multiset<int>::iterator it;
vector<int> v[MAXN];

signed main () {
	cin >> n >> k;
	for(register int i = 1;i <= n; ++i) {
		cin >> m[i];
		S.insert(m[i]);
	}
	for(register int i = 1;i <= k; ++i)
		cin >> c[i];
	while(S.size()) {
		tot++;
		ans = 0;
		for(register int i = k;i >= 1; --i) {
			if(!S.size()) break;
			while(ans < c[i]) {
				it = S.find(i);
				if(it == S.end()) break;
				v[tot].push_back(*it);
				S.erase(S.find(*it));
				ans++;
			}
		}
	}
	cout << tot << endl;
	for(register int i = 1;i <= tot; ++i) {
		int len = v[i].size();
		cout << len << ' ';
		for(register int j = 0;j < len; ++j)
			cout << v[i][j] << ' ';
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;

vector<int> cnt[maxn];
struct node {
    int pos;
    bool operator<(const node &ope) const {
        return cnt[pos].size() < cnt[ope.pos].size();
    }
};
priority_queue<node> q;
int c[maxn], m[maxn];
bool cmp(int a, int b){
    return a > b;
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &m[i]);
    for(int i = 1; i <= k; ++i)
        scanf("%d", &c[i]);
    sort(m + 1, m + 1 + n, cmp);

    int tmp = 1; q.push({1});
    for(int i = 1; i <= n; ++i) {
        int pos = q.top().pos, ans = cnt[pos].size();
        if(cnt[pos].size() < c[m[i]]) {
            while(cnt[pos].size() < c[m[i]])
                cnt[pos].push_back(m[i]), i += 1;
            i -= 1;
            q.pop(); q.push({pos});
        }else{
            tmp += 1;
            while(cnt[tmp].size() < c[m[i]])
                cnt[tmp].push_back(m[i]), i += 1;
            i -= 1;
            q.push({tmp});
        }
    }
    printf("%d\n", tmp);
    for(int i = 1; i <= tmp; ++i) {
        printf("%d", cnt[i].size());
        for(auto j : cnt[i])
            printf(" %d", j);
        puts("");
    }
    return 0;
}

/*

 */


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const int maxm = 3e6 + 5;
const ll mod   = 998244353;

ll fac[maxn];
ll inv[maxn];

ll fpow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1)   ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

void get(int n) {
    fac[0] = 1;
    for(ll i = 1ll; i <= n; ++i)
        fac[i] = fac[i - 1] * i % mod;

    inv[n] = fpow(fac[n], mod - 2);
    for(ll i = n - 1; i >= 0; --i)
        inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(int n, int m) {
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
    // return fac[n] * fpow(fac[m] * fac[n - m] % mod, mod - 2) % mod;
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    get(n);
    if(k == 0) {
        printf("%lld\n", fac[n]);
    }else if(k >= n) {
        puts("0");
    }else{
        ll ans = 0, f = 1ll;
        for(int i = 0; i < n - k; ++i, f = -f) {
            ans = (ans + f * fpow(n - k - i, n) * C(n - k, i) % mod) % mod;
        }
        ans = ((2ll * ans % mod * C(n, n - k) % mod) + mod) % mod;
        printf("%lld\n", ans);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;

vector<int> cnt[maxn];
struct node {
    int pos;
    bool operator<(const node &ope) const {
        return cnt[pos] < cnt[ope.pos];
    }
};
priority_queue<node> q;
int c[maxn], m[maxn];
bool cmp(int a, int b){
    return a > b;
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &m[i]);
    for(int i = 1; i <= k; ++i)
        scanf("%d", &c[i]);
    sort(m + 1, m + 1 + n, cmp);

    int tmp = 1; q.push({1});
    for(int i = 1; i <= n; ++i) {
        int pos = q.top().pos, ans = cnt[pos].size();
        if(cnt[pos].size() < c[m[i]]) {
            while(cnt[pos].size() < c[m[i]])
                cnt[pos].push_back(m[i]), i += 1;
            i -= 1;
            q.pop(); q.push({pos});
        }else{
            tmp += 1;
            while(cnt[tmp].size() < c[m[i]])
                cnt[tmp].push_back(m[i]), i += 1;
            i -= 1;
            q.push({tmp});
        }
    }
    printf("%d\n", tmp);
    for(int i = 1; i <= tmp; ++i) {
        printf("%d", cnt[i].size());
        for(auto j : cnt[i])
            printf(" %d", j);
        puts("");
    }
    return 0;
}

/*

 */


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500 + 5;
const int inf = 0x3f3f3f3f;

vector<int> cnt[maxn];
struct node {
    int pos;
    bool operator<(const node &ope) const {
        return cnt[pos] < cnt[ope.pos];
    }
};
priority_queue<node> q;
int c[maxn], m[maxn];
bool cmp(int a, int b){
    return a > b;
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &m[i]);
    for(int i = 1; i <= k; ++i)
        scanf("%d", &c[i]);
    sort(m + 1, m + 1 + n, cmp);

    int tmp = 1; q.push({1});
    for(int i = 1; i <= n; ++i) {
        int pos = q.top().pos, ans = cnt[pos].size();
        if(cnt[pos].size() < c[m[i]]) {
            while(cnt[pos].size() < c[m[i]])
                cnt[pos].push_back(m[i]), i += 1;
            i -= 1;
            q.pop(); q.push({pos});
        }else{
            tmp += 1;
            while(cnt[tmp].size() < c[m[i]])
                cnt[tmp].push_back(m[i]), i += 1;
            i -= 1;
            q.push({tmp});
        }
    }
    printf("%d\n", tmp);
    for(int i = 1; i <= tmp; ++i) {
        printf("%d", cnt[i].size());
        for(auto j : cnt[i])
            printf(" %d", j);
        puts("");
    }
    return 0;
}

/*
1
7 10 2
7 8
100 200
 */


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
int n, k;
int m[maxn], c[maxn];
vector<int> ans[maxn];
struct Que{
    int id;
    friend bool operator < (Que a, Que b)
    {
        return ans[a.id].size()>ans[b.id].size();
    }
};
priority_queue<Que> q;
int main()
{
    //freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &m[i]);
    sort(m+1, m+1+n, greater<int>());
    for(int i = 1; i <= k; i++) scanf("%d", &c[i]);
    int cnt = 1;
    q.push({1});
    for(int i = 1; i <= n; i++)
    {
        int id = q.top().id;
        if(ans[id].size()<c[m[i]])//当前还可填，一直填到不能填
        {
            while(ans[id].size()<c[m[i]]) ans[id].push_back(m[i]), i++;
            i--;
            q.pop();
            q.push({id});
        }
        else//增加新的分组，一直填
        {
            cnt++;
            while(ans[cnt].size()<c[m[i]]) ans[cnt].push_back(m[i]), i++;
            i--;
            q.push({cnt});
        }
    }
    printf("%d\n", cnt);
    for(int i = 1; i <= cnt; i++)
    {
        printf("%d", ans[i].size());
        for(auto e : ans[i]) printf(" %d", e);
        printf("\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;

vector<int> cnt[maxn];
struct node {
    int pos;
    bool operator<(const node &ope) const {
        return cnt[pos].size() > cnt[ope.pos].size();
    }
};
priority_queue<node> q;
int c[maxn], m[maxn];
bool cmp(int a, int b){
    return a > b;
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &m[i]);
    for(int i = 1; i <= k; ++i)
        scanf("%d", &c[i]);
    sort(m + 1, m + 1 + n, cmp);

    int tmp = 1; q.push({1});
    for(int i = 1; i <= n; ++i) {
        int pos = q.top().pos;
        if(cnt[pos].size() < c[m[i]]) {
            while(cnt[pos].size() < c[m[i]])
                cnt[pos].push_back(m[i]), i += 1;
            i -= 1;
            q.pop(); q.push({pos});
        }else{
            tmp += 1;
            while(cnt[tmp].size() < c[m[i]])
                cnt[tmp].push_back(m[i]), i += 1;
            i -= 1;
            q.push({tmp});
        }
    }
    printf("%d\n", tmp);
    for(int i = 1; i <= tmp; ++i) {
        printf("%d", cnt[i].size());
        for(auto j : cnt[i])
            printf(" %d", j);
        puts("");
    }
    return 0;
}

/*

 */


#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, k;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    while(tc--) {
        scanf("%d%d", &n, &k);
        vector<int> arr(n);
        for(int &x : arr) scanf("%d", &x);
        sort(arr.begin(), arr.end());
        vector<int> cnt(k + 1, 0);
        for(int i = 1; i <= k; i++) scanf("%d", &cnt[i]);
        int mn = cnt[1];
        vector<vector<int>> res;
        vector<int> cur;
        for(int i = 0; i < n; i++) {
            mn = min(mn, cnt[arr[i]]);
            if(mn) mn--, cur.push_back(arr[i]);
            else {
                res.push_back(cur);
                cur = {arr[i]};
                mn = cnt[arr[i]] - 1;
            }
        }
        if(cur.size()) res.push_back(cur);
        printf("%d\n", res.size());
        for(int i = 0; i < res.size(); i++) {
            printf("%d ", res[i].size());
            for(int x : res[i]) printf("%d ", x);
            puts("");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, k, cntt[N], cnt[N];
pair<int, int> tree[N << 2];

void build(int x = 1, int l = 1, int r = k) {
    if(l == r) {
        tree[x] = {cntt[l], (cntt[l] ? l : -1)};
        return;
    }
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    tree[x].first = max(tree[x << 1].first, tree[x << 1 | 1].first);
    tree[x].second = max(tree[x << 1].second, tree[x << 1 | 1].second);
}

void upd(int i, int v, int x = 1, int l = 1, int r = k) {
    if(l == r) {
        tree[x].first += v;
        if(!tree[x].first) tree[x].second = -1;
        return;
    }
    int mid = (l + r) >> 1;
    if(i <= mid) upd(i, v, x << 1, l, mid);
    else upd(i, v, x << 1 | 1, mid + 1, r);
    tree[x].first = max(tree[x << 1].first, tree[x << 1 | 1].first);
    tree[x].second = max(tree[x << 1].second, tree[x << 1 | 1].second);
}

int query(int i, int j, int x = 1, int l = 1, int r = k) {
    if(l >= i && r <= j) return tree[x].second;
    if(l > j || i > r) return -1;
    int mid = (l + r) >> 1;
    return max(query(i, j, x << 1, l, mid), query(i, j, x << 1 | 1, mid + 1, r));
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    while(tc--) {
        scanf("%d%d", &n, &k);
        for(int i = 0; i < n; i++) {
            int x; scanf("%d", &x);
            cntt[x]++;
        }
        build();
        for(int i = 0; i < k; i++) scanf("%d", &cnt[i]);
        reverse(cnt, cnt + k);
        vector<vector<int>> res;
        while(1) {
            int sub = 0;
            vector<int> cur;
            while(1) {
                int i = k - (upper_bound(cnt, cnt + k, sub) - cnt);
                if(!i) break;
                int j = query(1, i);
                if(j < 0) break;
                int can = min(cntt[j], cnt[k - j] - sub);
                if(!can) break;
                upd(j, -can);
                cntt[j] -= can;
                sub += can;
                while(can--) cur.push_back(j);
            }
            if(!cur.size()) break;
            res.push_back(cur);
        }
        printf("%d\n", res.size());
        for(int i = 0; i < res.size(); i++) {
            printf("%d ", res[i].size());
            for(int x : res[i]) printf("%d ", x);
            puts("");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, k;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    while(tc--) {
        scanf("%d%d", &n, &k);
        vector<int> arr(n);
        for(int &x : arr) scanf("%d", &x);
        sort(arr.rbegin(), arr.rend());
        vector<int> cnt(k + 1, 0);
        for(int i = 1; i <= k; i++) scanf("%d", &cnt[i]);
        int mn = cnt[1];
        vector<vector<int>> res;
        vector<int> cur;
        for(int i = 0; i < n; i++) {
            mn = min(mn, cnt[arr[i]]);
            if(mn) mn--, cur.push_back(arr[i]);
            else {
                res.push_back(cur);
                cur = {arr[i]};
                mn = cnt[arr[i]] - 1;
            }
        }
        if(cur.size()) res.push_back(cur);
        printf("%d\n", res.size());
        for(int i = 0; i < res.size(); i++) {
            printf("%d ", res[i].size());
            for(int x : res[i]) printf("%d ", x);
            puts("");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, k;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    while(tc--) {
        scanf("%d%d", &n, &k);
        vector<int> arr(n);
        for(int &x : arr) scanf("%d", &x);
        sort(arr.rbegin(), arr.rend());
        vector<int> cnt(k + 1, 0);
        for(int i = 1; i <= k; i++) scanf("%d", &cnt[i]);
        int sub = 0;
        vector<vector<int>> res;
        vector<int> cur;
        for(int i = 0; i < n; i++) {
            int c = cnt[arr[i]] - sub;
            if(c) sub++, cur.push_back(arr[i]);
            else {
                sub = 1;
                res.push_back(cur);
                cur = {arr[i]};
            }
        }
        if(cur.size()) res.push_back(cur);
        printf("%d\n", res.size());
        for(int i = 0; i < res.size(); i++) {
            printf("%d ", res[i].size());
            for(int x : res[i]) printf("%d ", x);
            puts("");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n, k;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    while(tc--) {
        scanf("%d%d", &n, &k);
        vector<int> arr(n);
        for(int &x : arr) scanf("%d", &x);
        vector<int> cnt(k + 1, 0);
        for(int i = 1; i <= k; i++) scanf("%d", &cnt[i]);
        int mn = cnt[1];
        vector<vector<int>> res;
        vector<int> cur;
        for(int i = 0; i < n; i++) {
            mn = min(mn, cnt[arr[i]]);
            if(mn) mn--, cur.push_back(arr[i]);
            else {
                res.push_back(cur);
                cur = {arr[i]};
                mn = cnt[arr[i]] - 1;
            }
        }
        if(cur.size()) res.push_back(cur);
        printf("%d\n", res.size());
        for(int i = 0; i < res.size(); i++) {
            printf("%d ", res[i].size());
            for(int x : res[i]) printf("%d ", x);
            puts("");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

const int maxn = 2e5+10;
int n,k,via[maxn],cnt;
int c[maxn];
vector<int> ans[maxn];

signed main()
{
    cin >> n >> k;
    for ( int i=0; i<n; i++ ) {
        int x;scanf("%lld",&x);
        via[x] ++;
    }
    for ( int i=1; i<=k; i++ ) scanf("%lld",&c[i]);
    c[0] = 0x3f3f3f3f;
    cnt = 0;
    while ( n>0 ) {
        int limit = 0x3f3f3f3f;
        int now = 0;
        for ( int i=k; i>=1; i-- ) {
            if ( via[i]==0 ) continue ;
            limit = min(c[i],c[i-1]-now);
            if ( now>=c[i] ) continue ;
            if ( via[i]<=limit ) {
                now += via[i];
                for ( int j=0; j<via[i]; j++ ) ans[cnt].push_back(i);
                via[i] = 0;
            }
            else if ( via[i]>limit ) {
                now += limit;
                for ( int j=0; j<limit; j++ ) ans[cnt].push_back(i);
                via[i] -= limit;
                limit = 0;
                break;
            }
        }
        n -= now;cnt++;
    }
    printf("%lld\n",cnt);
    for ( int i=0; i<cnt; i++ ) {
        printf("%lld ",ans[i].size());
        for ( int j=0; j<ans[i].size(); j++ ) {
            printf("%lld ",ans[i][j]);
        }
        printf("\n");
    }

    return 0;
}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

int32_t main()
{
	fio;
	int n,k;
	cin>>n>>k;
	int *a=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	sort(a,a+n);
	int ans=a[n-1]-a[0];

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<a[i]<<" ";
	// }
	// cout<<endl;

	vector<int> diff;
	for(int i=0;i<n/2+(n%2);i++)
	{
		diff.push_back(a[n-1-i]-a[i]);
	}

	int l=diff.size();

	// for(int i=0;i<l;i++)
	// {
	// 	cout<<diff[i]<<" ";
	// }
	// cout<<endl;

	for(int i=1;i<l;i++)
	{
		if(k<=0)
		{
			break;
		}
		int d=diff[i-1]-diff[i];
		d=d*i;
		if(k>=d)
		{
			k-=d;
			ans=diff[i];
		}
		else
		{
			ans=diff[i-1];
			break;
		}
	}

	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int *a=new int[n];
    int minm=0;
    int maxm=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	maxm=max(maxm,a[i]);
    }

    int diff=LLONG_MAX;
    while(minm<=maxm)
    {
    	int mid=minm+(maxm-minm)/2;
    	int steps=0;
    	int *temp=new int[n];

    	for(int i=0;i<n;i++)
    	{
    		if(a[i]>=mid)
    		{
    			steps+=a[i]-mid;
    			temp[i]=mid;
    		}
    		else
    		{
    			temp[i]=a[i];
    		}
    	}

    	if(steps<=k)
    	{
    		int p=maxm,q=0;

    		// cout<<"First "<<mid<<endl;
    		// for(int i=0;i<n;i++)
    		// {
    		// 	cout<<temp[i]<<" ";
    		// }
    		// cout<<endl;

    		while(q<=p)
    		{
    			int s=steps;
    			int mid1=q+(p-q)/2;
    			int *temp1=new int[n];
    			int p1=LLONG_MIN,q1=LLONG_MAX;
    			for(int i=0;i<n;i++)
		    	{
		    		if(temp[i]<=mid1)
		    		{
		    			s+=mid1-temp[i];
		    			temp1[i]=mid1;
		    		}
		    		else
		    		{
		    			temp1[i]=temp[i];
		    		}
		    		p1=max(p1,temp1[i]);
		    		q1=min(q1,temp1[i]);
		    	}

		    	if(s<=k)
		    	{
		    		// cout<<"Second "<<mid1<<endl;
		    		// for(int i=0;i<n;i++)
		    		// {
		    		// 	cout<<temp1[i]<<" ";
		    		// }
		    		// cout<<endl;

		    		diff=min(diff,p1-q1);
		    		q=mid1+1;
		    	}
		    	else
		    	{
		    		p=mid1-1;
		    	}

		    	delete[] temp1;
    		}

    		maxm=mid-1;
    	}
    	else
    	{
    		minm=mid+1;
    	}

    	delete[] temp;
    }

    cout<<diff<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int *a=new int[n];
    int minm=0;
    int maxm=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	maxm=max(maxm,a[i]);
    }

    int diff=LLONG_MAX;
    while(minm<=maxm)
    {
    	int mid=minm+(maxm-minm)/2;
    	int steps=0;
    	int *temp=new int[n];
    	int p=LLONG_MIN,q=0;
    	for(int i=0;i<n;i++)
    	{
    		if(a[i]>=mid)
    		{
    			steps+=a[i]-mid;
    			temp[i]=mid;
    		}
    		else
    		{
    			temp[i]=a[i];
    		}
    		p=max(p,temp[i]);
    	}

    	if(steps<=k)
    	{
    		diff=min(diff,p-q);

    		// cout<<"First "<<mid<<endl;
    		// for(int i=0;i<n;i++)
    		// {
    		// 	cout<<temp[i]<<" ";
    		// }
    		// cout<<endl;

    		while(q<=p)
    		{
    			int s=steps;
    			int mid1=q+(p-q)/2;
    			int *temp1=new int[n];
    			int p1=LLONG_MIN,q1=LLONG_MAX;
    			for(int i=0;i<n;i++)
		    	{
		    		if(temp[i]<=mid1)
		    		{
		    			s+=mid1-temp[i];
		    			temp1[i]=mid1;
		    		}
		    		else
		    		{
		    			temp1[i]=temp[i];
		    		}
		    		p1=max(p1,temp1[i]);
		    		q1=min(q1,temp1[i]);
		    	}

		    	if(s<=k)
		    	{
		    		// cout<<"Second "<<mid1<<endl;
		    		// for(int i=0;i<n;i++)
		    		// {
		    		// 	cout<<temp1[i]<<" ";
		    		// }
		    		// cout<<endl;

		    		diff=min(diff,p1-q1);
		    		q=mid1+1;
		    	}
		    	else
		    	{
		    		p=mid1-1;
		    	}

		    	delete[] temp1;
    		}

    		maxm=mid-1;
    	}
    	else
    	{
    		minm=mid+1;
    	}

    	delete[] temp;
    }

    cout<<diff<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int *a=new int[n];
    int minm=LLONG_MAX;
    int maxm=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	minm=min(minm,a[i]);
    	maxm=max(maxm,a[i]);
    }

    int diff=LLONG_MAX;
    while(minm<=maxm)
    {
    	int mid=minm+(maxm-minm)/2;
    	int steps=0;
    	int *temp=new int[n];
    	int p=LLONG_MIN,q=LLONG_MAX;
    	for(int i=0;i<n;i++)
    	{
    		if(a[i]>=mid)
    		{
    			steps+=a[i]-mid;
    			temp[i]=mid;
    		}
    		else
    		{
    			temp[i]=a[i];
    		}
    		p=max(p,temp[i]);
    		q=min(q,temp[i]);
    	}

    	if(steps<=k)
    	{
    		diff=min(diff,p-q);

    		// cout<<"First "<<mid<<endl;
    		// for(int i=0;i<n;i++)
    		// {
    		// 	cout<<temp[i]<<" ";
    		// }
    		// cout<<endl;

    		while(q<=p)
    		{
    			int s=steps;
    			int mid1=q+(p-q)/2;
    			int *temp1=new int[n];
    			int p1=LLONG_MIN,q1=LLONG_MAX;
    			for(int i=0;i<n;i++)
		    	{
		    		if(temp[i]<=mid1)
		    		{
		    			s+=mid1-temp[i];
		    			temp1[i]=mid1;
		    		}
		    		else
		    		{
		    			temp1[i]=temp[i];
		    		}
		    		p1=max(p1,temp1[i]);
		    		q1=min(q1,temp1[i]);
		    	}

		    	if(s<=k)
		    	{
		    		// cout<<"Second "<<mid1<<endl;
		    		// for(int i=0;i<n;i++)
		    		// {
		    		// 	cout<<temp1[i]<<" ";
		    		// }
		    		// cout<<endl;

		    		diff=min(diff,p1-q1);
		    		p=mid1-1;
		    	}
		    	else
		    	{
		    		q=mid1+1;
		    	}

		    	delete[] temp1;
    		}

    		maxm=mid-1;
    	}
    	else
    	{
    		minm=mid+1;
    	}

    	delete[] temp;
    }

    cout<<diff<<endl;
	return 0;
}


// #include <bits/stdc++.h>
// #define int long long int
// using namespace std;

// int32_t main()
// {
// 	ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     int n,k;
//     cin>>n>>k;
//     int *a=new int[n];
//     int minm=0;
//     int maxm=LLONG_MIN;
//     for(int i=0;i<n;i++)
//     {
//     	cin>>a[i];
//     	maxm=max(maxm,a[i]);
//     }

//     int diff=LLONG_MAX;
//     while(minm<=maxm)
//     {
//     	int mid=minm+(maxm-minm)/2;
//     	int steps=0;
//     	int *temp=new int[n];

//     	for(int i=0;i<n;i++)
//     	{
//     		if(a[i]<=mid)
//     		{
//     			steps+=mid-a[i];
//     			temp[i]=mid;
//     		}
//     		else
//     		{
//     			temp[i]=a[i];
//     		}
//     	}

//     	if(steps<=k)
//     	{
//     		int p=maxm,q=0;

//     		// cout<<"First "<<mid<<endl;
//     		// for(int i=0;i<n;i++)
//     		// {
//     		// 	cout<<temp[i]<<" ";
//     		// }
//     		// cout<<endl;

//     		while(q<=p)
//     		{
//     			int s=steps;
//     			int mid1=q+(p-q)/2;
//     			int *temp1=new int[n];
//     			int p1=LLONG_MIN,q1=LLONG_MAX;
//     			for(int i=0;i<n;i++)
// 		    	{
// 		    		if(temp[i]<=mid1)
// 		    		{
// 		    			s+=mid1-temp[i];
// 		    			temp1[i]=mid1;
// 		    		}
// 		    		else
// 		    		{
// 		    			temp1[i]=temp[i];
// 		    		}
// 		    		p1=max(p1,temp1[i]);
// 		    		q1=min(q1,temp1[i]);
// 		    	}

// 		    	if(s<=k)
// 		    	{
// 		    		// cout<<"Second "<<mid1<<endl;
// 		    		// for(int i=0;i<n;i++)
// 		    		// {
// 		    		// 	cout<<temp1[i]<<" ";
// 		    		// }
// 		    		// cout<<endl;

// 		    		diff=min(diff,p1-q1);
// 		    		q=mid1+1;
// 		    	}
// 		    	else
// 		    	{
// 		    		p=mid1-1;
// 		    	}

// 		    	delete[] temp1;
//     		}

//     		maxm=mid-1;
//     	}
//     	else
//     	{
//     		minm=mid+1;
//     	}

//     	delete[] temp;
//     }

//     cout<<diff<<endl;
// 	return 0;
// }

#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

int32_t main()
{
	fio;
	int n,k;
	cin>>n>>k;
	int *a=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	sort(a,a+n);
	int ans=a[n-1]-a[0];

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<a[i]<<" ";
	// }
	// cout<<endl;

	vector<int> diff;
	for(int i=0;i<n/2+(n%2);i++)
	{
		diff.push_back(a[n-1-i]-a[i]);
	}

	int l=diff.size();

	// for(int i=0;i<l;i++)
	// {
	// 	cout<<diff[i]<<" ";
	// }
	// cout<<endl;

	for(int i=1;i<l;i++)
	{
		if(k<=0)
		{
			break;
		}
		int d=diff[i-1]-diff[i];
		d=d*i;
		if(k>=d)
		{
			k-=d;
			ans=diff[i];
		}
		else
		{
			ans=diff[i-1]-(k/i);
			break;
		}
	}

	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int *a=new int[n];
    int minm=0;
    int maxm=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	maxm=max(maxm,a[i]);
    }

    int diff=LLONG_MAX;
    while(minm<=maxm)
    {
    	int mid=minm+(maxm-minm)/2;
    	int steps=0;
    	int *temp=new int[n];
    	int p=LLONG_MIN,q=LLONG_MAX;
    	for(int i=0;i<n;i++)
    	{
    		if(a[i]>=mid)
    		{
    			steps+=a[i]-mid;
    			temp[i]=mid;
    		}
    		else
    		{
    			temp[i]=a[i];
    		}
    		p=max(p,temp[i]);
    		q=min(q,temp[i]);
    	}

    	if(steps<=k)
    	{
    		diff=min(diff,p-q);

    		// cout<<"First "<<mid<<endl;
    		// for(int i=0;i<n;i++)
    		// {
    		// 	cout<<temp[i]<<" ";
    		// }
    		// cout<<endl;

    		while(q<=p)
    		{
    			int s=steps;
    			int mid1=q+(p-q)/2;
    			int *temp1=new int[n];
    			int p1=LLONG_MIN,q1=LLONG_MAX;
    			for(int i=0;i<n;i++)
		    	{
		    		if(temp[i]<=mid1)
		    		{
		    			s+=mid1-temp[i];
		    			temp1[i]=mid1;
		    		}
		    		else
		    		{
		    			temp1[i]=temp[i];
		    		}
		    		p1=max(p1,temp1[i]);
		    		q1=min(q1,temp1[i]);
		    	}

		    	if(s<=k)
		    	{
		    		// cout<<"Second "<<mid1<<endl;
		    		// for(int i=0;i<n;i++)
		    		// {
		    		// 	cout<<temp1[i]<<" ";
		    		// }
		    		// cout<<endl;

		    		diff=min(diff,p1-q1);
		    		q=mid1+1;
		    	}
		    	else
		    	{
		    		p=mid1-1;
		    	}

		    	delete[] temp1;
    		}

    		maxm=mid-1;
    	}
    	else
    	{
    		minm=mid+1;
    	}

    	delete[] temp;
    }

    cout<<diff<<endl;
	return 0;
}


#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

int32_t main()
{
	fio;
	int n,k;
	cin>>n>>k;
	int *a=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	sort(a,a+n);
	int ans=a[n-1]-a[0];

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<a[i]<<" ";
	// }
	// cout<<endl;

	vector<int> diff;
	for(int i=0;i<n/2;i++)
	{
		diff.push_back(a[n-1-i]-a[i]);
	}
	diff.push_back(0);

	int l=diff.size();

	// for(int i=0;i<l;i++)
	// {
	// 	cout<<diff[i]<<" ";
	// }
	// cout<<endl;

	for(int i=1;i<l;i++)
	{
		if(k<=0)
		{
			break;
		}
		int d=diff[i-1]-diff[i];
		d=d*i;
		if(k>=d)
		{
			k-=d;
			ans=diff[i];
		}
		else
		{
			ans=diff[i-1]-(k/i);
			break;
		}
	}

	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int *a=new int[n];
    int minm=LLONG_MAX;
    int maxm=LLONG_MIN;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	minm=min(minm,a[i]);
    	maxm=max(maxm,a[i]);
    }

    int diff=LLONG_MAX;
    while(minm<=maxm)
    {
    	int mid=minm+(maxm-minm)/2;
    	int steps=0;
    	int *temp=new int[n];
    	int p=LLONG_MIN,q=LLONG_MAX;
    	for(int i=0;i<n;i++)
    	{
    		if(a[i]>=mid)
    		{
    			steps+=a[i]-mid;
    			temp[i]=mid;
    		}
    		else
    		{
    			temp[i]=a[i];
    		}
    		p=max(p,temp[i]);
    		q=min(q,temp[i]);
    	}

    	if(steps<=k)
    	{
    		while(q<=p)
    		{
    			int s=steps;
    			int mid1=q+(p-q)/2;
    			int *temp1=new int[n];
    			int p1=LLONG_MIN,q1=LLONG_MAX;
    			for(int i=0;i<n;i++)
		    	{
		    		if(temp[i]<=mid1)
		    		{
		    			s+=mid1-temp[i];
		    			temp1[i]=mid1;
		    		}
		    		else
		    		{
		    			temp1[i]=temp[i];
		    		}
		    		p1=max(p1,temp1[i]);
		    		q1=min(q1,temp1[i]);
		    	}

		    	if(s<=k)
		    	{
		    		diff=min(diff,p1-q1);
		    		p=mid1-1;
		    	}
		    	else
		    	{
		    		q=mid1+1;
		    	}

		    	delete[] temp1;
    		}

    		maxm=mid-1;
    	}
    	else
    	{
    		minm=mid+1;
    	}

    	delete[] temp;
    }

    cout<<diff<<endl;
	return 0;
}


// #include <bits/stdc++.h>
// #define int long long int
// using namespace std;

// int32_t main()
// {
// 	ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     int n,k;
//     cin>>n>>k;
//     int *a=new int[n];
//     int minm=0;
//     int maxm=LLONG_MIN;
//     for(int i=0;i<n;i++)
//     {
//     	cin>>a[i];
//     	maxm=max(maxm,a[i]);
//     }

//     int diff=LLONG_MAX;
//     while(minm<=maxm)
//     {
//     	int mid=minm+(maxm-minm)/2;
//     	int steps=0;
//     	int *temp=new int[n];

//     	for(int i=0;i<n;i++)
//     	{
//     		if(a[i]<=mid)
//     		{
//     			steps+=mid-a[i];
//     			temp[i]=mid;
//     		}
//     		else
//     		{
//     			temp[i]=a[i];
//     		}
//     	}

//     	if(steps<=k)
//     	{
//     		int p=maxm,q=0;

//     		// cout<<"First "<<mid<<endl;
//     		// for(int i=0;i<n;i++)
//     		// {
//     		// 	cout<<temp[i]<<" ";
//     		// }
//     		// cout<<endl;

//     		while(q<=p)
//     		{
//     			int s=steps;
//     			int mid1=q+(p-q)/2;
//     			int *temp1=new int[n];
//     			int p1=LLONG_MIN,q1=LLONG_MAX;
//     			for(int i=0;i<n;i++)
// 		    	{
// 		    		if(temp[i]<=mid1)
// 		    		{
// 		    			s+=mid1-temp[i];
// 		    			temp1[i]=mid1;
// 		    		}
// 		    		else
// 		    		{
// 		    			temp1[i]=temp[i];
// 		    		}
// 		    		p1=max(p1,temp1[i]);
// 		    		q1=min(q1,temp1[i]);
// 		    	}

// 		    	if(s<=k)
// 		    	{
// 		    		// cout<<"Second "<<mid1<<endl;
// 		    		// for(int i=0;i<n;i++)
// 		    		// {
// 		    		// 	cout<<temp1[i]<<" ";
// 		    		// }
// 		    		// cout<<endl;

// 		    		diff=min(diff,p1-q1);
// 		    		q=mid1+1;
// 		    	}
// 		    	else
// 		    	{
// 		    		p=mid1-1;
// 		    	}

// 		    	delete[] temp1;
//     		}

//     		maxm=mid-1;
//     	}
//     	else
//     	{
//     		minm=mid+1;
//     	}

//     	delete[] temp;
//     }

//     cout<<diff<<endl;
// 	return 0;
// }

#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

int32_t main()
{
	fio;
	int n,k;
	cin>>n>>k;
	int *a=new int[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}

	sort(a,a+n);
	int ans=a[n-1]-a[0];

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<a[i]<<" ";
	// }
	// cout<<endl;

	vector<int> diff;
	for(int i=0;i<n/2+(n%2);i++)
	{
		diff.push_back(a[n-1-i]-a[i]);
	}

	int l=diff.size();

	// for(int i=0;i<l;i++)
	// {
	// 	cout<<diff[i]<<" ";
	// }
	// cout<<endl;

	for(int i=1;i<l;i++)
	{
		if(k<=0)
		{
			break;
		}
		int d=diff[i-1]-diff[i];
		d=d*i;
		if(k>=d)
		{
			k-=d;
			ans=diff[i];
		}
		else
		{
			if(k%i==0)
			{
				ans=diff[i-1]-(k/i);
			}
			else
			{
				ans=diff[i-1];
			}
			break;
		}
	}

	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if(!valmx && !valmn)
            break;
        if(p1 == p2)
            break;
        if(valmx >= valmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            // cout << v[p2] << " " << valmx << " " << ok << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 0;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << " " << ok << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if(!valmx && !valmn)
            break;
        if(p1 == p2)
            break;
        if(valmx > valmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            // cout << v[p2] << " " << valmx << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 1;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
	#ifdef local
		freopen(".in", "r", stdin);
		//freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> n >> k;
	rep(i, 1, n) {
		int x;
		cin >> x;
		++cnt[x];
		v.pb(x);
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	int p1 = 0, p2 = sz(v)-1;
	while(true) {
		int kolmx = cnt[v[p2]];
		ll valmx = k/kolmx;
		int kolmn = cnt[v[p1]];
		ll valmn = k/kolmn;
		if(!valmx && !valmn)
			break;
		if(v[p1] == v[p2] || p1 == p2)
			break;
		bool okmx = v[p2]-valmx < v[p2-1];
		bool okmn = v[p1]+valmn > v[p1+1];
		if(valmx > valmn) {
			if(okmx)
				valmx = v[p2]-v[p2-1];
			cnt[v[p2]-valmx] += cnt[v[p2]];
			cnt[v[p2]] = 0;
			k -= valmx*kolmx;
			--p2;
			// cout << 1 << " " << valmx << nxtl;
		} else if(valmx < valmn) {
			if(okmn)
				valmn = v[p1+1]-v[p1];
			cnt[v[p1]+valmn] += cnt[v[p1]];
			cnt[v[p1]] = 0;
			k -= valmn*kolmn;
			++p1;
			// cout << 2 << " " << valmn << nxtl;
		} else {
			if(okmx) {
				if(okmx)
					valmx = v[p2]-v[p2-1];
				cnt[v[p2]-valmx] += cnt[v[p2]];
				cnt[v[p2]] = 0;
				k -= valmx*kolmx;
				--p2;
				// cout << 1 << " " << valmx << nxtl;
			} else {
				if(okmn)
					valmn = v[p1+1]-v[p1];
				cnt[v[p1]+valmn] += cnt[v[p1]];
				cnt[v[p1]] = 0;
				k -= valmn*kolmn;
				++p1;
				// cout << 2 << " " << valmn << nxtl;
			}
		}
	}
	cout << v[p2]-v[p1] << nxtl;
	return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if(!valmx && !valmn)
            break;
        if(p1 == p2)
            break;
        if(valmx >= valmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            // cout << v[p2] << " " << valmx << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 1;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
	#ifdef local
		freopen(".in", "r", stdin);
		//freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> n >> k;
	rep(i, 1, n) {
		int x;
		cin >> x;
		++cnt[x];
		v.pb(x);
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
	int p1 = 0, p2 = sz(v)-1;
	while(true) {
		int kolmx = cnt[v[p2]];
		ll valmx = k/kolmx;
		int kolmn = cnt[v[p1]];
		ll valmn = k/kolmn;
		if(!valmx && !valmn)
			break;
		if(v[p1] == v[p2] || p1 == p2)
			break;
		if(valmx > valmn) {
			if(v[p2]-valmx < v[p2-1])
				valmx = v[p2]-v[p2-1];
			cnt[v[p2]-valmx] += cnt[v[p2]];
			cnt[v[p2]] = 0;
			k -= valmx*kolmx;
			--p2;
			// cout << 1 << " " << valmx << nxtl;
		} else {
			if(v[p1]+valmn > v[p1+1])
				valmn = v[p1+1]-v[p1];
			cnt[v[p1]+valmn] += cnt[v[p1]];
			cnt[v[p1]] = 0;
			k -= valmn*kolmn;
			++p1;
			// cout << 2 << " " << valmn << nxtl;
		}
	}
	cout << v[p2]-v[p1] << nxtl;
	return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(k) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if(!valmx && !valmn)
            break;
        if(v[p1] == v[p2] || p1 == p2)
            break;
        if(valmx > valmn) {
            if(v[p2]-valmx < v[p2-1])
                valmx = v[p2]-v[p2-1];
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            --p2;
            // cout << 1 << " " << valmx << nxtl;
        } else {
            if(v[p1]+valmn > v[p1+1])
                valmn = v[p1+1]-v[p1];
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            ++p1;
            // cout << 2 << " " << valmn << nxtl;
        }
    }
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if((!valmx && !valmn) || p1 == p2)
            break;
        if(kolmx >= kolmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            // cout << v[p2] << " " << valmx << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 1;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
unordered_map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if(!valmx && !valmn)
            break;
        if(p1 == p2)
            break;
        if(valmx >= valmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            // cout << v[p2] << " " << valmx << " " << ok << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 0;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << " " << ok << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if((!valmx && !valmn) || p1 == p2)
            break;
        if(kolmx > kolmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            // cout << v[p2] << " " << valmx << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 1;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define per(i, n, a) for(int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)2e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n;
ll k;
map < int, int > cnt;
vector < int > v;

int main() {
    #ifdef local
        freopen(".in", "r", stdin);
        //freopen(".out", "w", stdout);
    #endif
    onlycin;
    cin >> n >> k;
    rep(i, 1, n) {
        int x;
        cin >> x;
        ++cnt[x];
        v.pb(x);
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    int p1 = 0, p2 = sz(v)-1;
    while(1) {
        int kolmx = cnt[v[p2]];
        ll valmx = k/kolmx;
        int kolmn = cnt[v[p1]];
        ll valmn = k/kolmn;
        if(!valmx && !valmn)
            break;
        if(p1 == p2)
            break;
        if(valmx >= valmn) {
            bool ok = 0;
            if(v[p2]-valmx < v[p2-1]) {
                ok = 1;
                valmx = v[p2]-v[p2-1];
            }
            cnt[v[p2]-valmx] += cnt[v[p2]];
            cnt[v[p2]] = 0;
            k -= valmx*kolmx;
            cout << v[p2] << " " << valmx << " " << ok << nxtl;
            if(ok)
                --p2;
            else
                v[p2] -= valmx;
        } else {
            bool ok = 0;
            if(v[p1]+valmn > v[p1+1]) {
                ok = 1;
                valmn = v[p1+1]-v[p1];
            }
            cnt[v[p1]+valmn] += cnt[v[p1]];
            cnt[v[p1]] = 0;
            k -= valmn*kolmn;
            // cout << v[p1] << " " << valmn << " " << ok << nxtl;
            if(ok)
                ++p1;
            else
                v[p1] += valmn;
        }
    }
    // cout << p1 << " " << p2 << nxtl;
    // cout << v[p1] << " " << v[p2] << nxtl;
    cout << v[p2]-v[p1] << nxtl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

ll n, arr[MAXN], k;
ll n1[MAXN], n2[MAXN];

void met() {
  return;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> mym;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  for (ll i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += i*(arr[i]-arr[i-1]);
    }
  }
  for (ll i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += (n-1-i)*(arr[i+1]-arr[i]);
    }
  }

  ll ans = arr[n-1]-arr[0];
  for (ll i = 0, j = 0; i < n; i++) {
    j = max(i, j);
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    if (j == n) break;
    ll rem = k-n1[i]-n2[j];
    ll sum = 0;
    if (i+1<n && i<j)
      sum = max (sum, min((ll)arr[i+1]-arr[i], rem/(i+1)));
    if (j>0 && j>i)
      sum = max (sum, min(ll(arr[j]-arr[j-1]), rem/(n-j)));
    ans = min((ll)arr[j]-arr[i] - sum,ans);
  }
  ans = max(ans, (ll)0);
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

ll n, arr[MAXN], k;
ll n1[MAXN], n2[MAXN];

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> mym;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  for (ll i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += i*(arr[i]-arr[i-1]);
    }
  }
  for (ll i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += (n-1-i)*(arr[i+1]-arr[i]);
    }
  }

  ll ans = arr[n-1]-arr[0];
  for (ll i = 0, j = 0; i < n; i++) {
    j = max(i, j);
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    if (j == n) break;
    ll rem = k-n1[i]-n2[j];
    ll sum = 0;
    if (i<j) {
      sum = max (sum, min(arr[i+1]-arr[i], rem/(i+1)));
      sum = max (sum, min(arr[j]-arr[j-1], rem/(n-j)));
    }
    assert(arr[j]-arr[i]-sum >= 0);
    ans = min((ll)arr[j]-arr[i] - sum, ans);
  }
  ans = max(ans, (ll)0);
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

int n, arr[MAXN]; ll k;
ll n1[MAXN], n2[MAXN];

void met() {
  return;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> mym;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  for (int i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += (ll)i*(arr[i]-arr[i-1]);
    }
    //cerr << n1[i] << " ";
  } //cerr << endl;
  for (int i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += (ll)(n-1-i)*(arr[i+1]-arr[i]);
    }
    //cerr << n2[i] << " ";
  } //cerr << endl;

  ll ans = arr[n-1]-arr[0];
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    if (j < n)
      ans = min((ll)arr[j]-arr[i],ans);
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

int n, arr[MAXN]; ll k;
ll n1[MAXN], n2[MAXN];

void met() {
  return;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> mym;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  for (int i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += i*(arr[i]-arr[i-1]);
    }
    //cerr << n1[i] << " ";
  } //cerr << endl;
  for (int i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += (n-1-i)*(arr[i+1]-arr[i]);
    }
    //cerr << n2[i] << " ";
  } //cerr << endl;

  ll ans = arr[n-1]-arr[0];
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    if (j < n)
      ans = min((ll)arr[j]-arr[i],ans);
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

int n, arr[MAXN]; ll k;
ll n1[MAXN], n2[MAXN];

void met() {
  return;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> mym;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  for (int i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += ((ll)i)*(arr[i]-arr[i-1]);
    }
    //cerr << n1[i] << " ";
  } //cerr << endl;
  for (int i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += ((ll)(n-1-i))*(arr[i+1]-arr[i]);
    }
    //cerr << n2[i] << " ";
  } //cerr << endl;

  ll ans = arr[n-1]-arr[0];
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    ll rem = k-n1[i]-n2[j];
    ll sum = 0;
    if (i+1<n && i<j)
      sum = max (sum, min((ll)arr[i+1]-arr[i], rem/(i+1)));
    if (j>0 && j < n && j>i)
      sum = max (sum, min(ll(arr[j]-arr[j-1]), rem/(n-j)));
    if (j < n)
      ans = min((ll)arr[j]-arr[i] - sum,ans);
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

ll n, arr[MAXN], k;
ll n1[MAXN], n2[MAXN];

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  // for (int i = 0; i < n; i++) {
  //   cerr << arr[i] << " ";
  // } cerr << endl;
  for (ll i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += i*(arr[i]-arr[i-1]);
    }
  }
  for (ll i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += (n-1-i)*(arr[i+1]-arr[i]);
    }
  }

  ll ans = arr[n-1]-arr[0];
  for (ll i = 0, j = 0; i < n; i++) {
    j = max(i, j);
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    if (j == n) break;
    ll rem = k-n1[i]-n2[j];
    ll sum = 0;
    if (i<j) {
      sum = max (sum, min(arr[i+1]-arr[i], rem/(i+1)));
      sum = max (sum, min(arr[j]-arr[j-1], rem/(n-j)));
    }
     //cerr << arr[i] << " " << arr[j] << " " << n1[i] << "  " << n2[j] << "      " << sum << " " << rem << endl;
    assert(arr[j]-arr[i]-sum >= 0);
    ans = min(arr[j]-arr[i] - sum, ans);
  }
  ans = max(ans, (ll)0);
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

ll n, arr[MAXN], k;
ll n1[MAXN], n2[MAXN];

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  int i = 0, j = n-1, ans = arr[j]-arr[i];
  while (k > 0 && arr[i] < arr[j]) {
    ll d = arr[i+1]-arr[i];
    ll r = min(k, d*(i+1));
    k-=r;
    ans-=r/(i+1);
    i++;
    if (k <= 0 || arr[i] == arr[j]) break;
    d = arr[j]-arr[j-1];
    r = min(k, d*i);
    k-=r;
    ans-=r/i;
    j--;
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1000006;

int n, arr[MAXN]; ll k;
ll n1[MAXN], n2[MAXN];

void met() {
  return;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, int> mym;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr+n);
  for (int i = 0; i < n; i++) {
    if (i) {
      n1[i] = n1[i-1];
      n1[i] += ((ll)i)*(arr[i]-arr[i-1]);
    }
    //cerr << n1[i] << " ";
  } //cerr << endl;
  for (int i = n-1; i >= 0; i--) {
    if (i < n-1) {
      n2[i] = n2[i+1];
      n2[i] += ((ll)(n-1-i))*(arr[i+1]-arr[i]);
    }
    //cerr << n2[i] << " ";
  } //cerr << endl;

  ll ans = arr[n-1]-arr[0];
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && n1[i]+n2[j] > k) {
      j++;
    }
    ll rem = k-n1[i]-n2[j];
    ll sum = 0;
    if (i+1<n) sum = max (sum, min((ll)arr[i+1]-arr[i], rem/(i+1)));
    if (j>0) sum = max (sum, min(ll(arr[j]-arr[j-1]), rem/(n-j)));
    if (j < n)
      ans = min((ll)arr[j]-arr[i] - sum,ans);
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n,k;
    cin >> n >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                int rid = k / stlen;
                k -= miN(rid*stlen, stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                int rid = k / edlen;
                k -= miN(rid*edlen, edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(st == ed-1) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n,k;
    cin >> n >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                int rid = k / stlen;
                k -= miN(rid*stlen, stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                int rid = k / edlen;
                k -= miN(rid*edlen, edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


 #include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    lld k;
    cin >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                int rid = k / stlen;
                k -= miN(rid*stlen, stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                int rid = k / edlen;
                k -= miN(rid*edlen, edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n;
    lld k;
    cin >> n;
    cin >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                lld rid = k / stlen;
                k -= miN(rid*stlen, (lld)stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                lld rid = k / edlen;
                k -= miN(rid*edlen, (lld)edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    ll k;
    cin >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                int rid = k / stlen;
                k -= miN(rid*stlen, stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                int rid = k / edlen;
                k -= miN(rid*edlen, edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n,k;
    ll k;
    cin >> n;
    cin >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                lld rid = k / stlen;
                k -= miN(rid*stlen, (lld)stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                lld rid = k / edlen;
                k -= miN(rid*edlen, (lld)edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n,k;
    lld k;
    cin >> n;
    cin >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                lld rid = k / stlen;
                k -= miN(rid*stlen, (lld)stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                lld rid = k / edlen;
                k -= miN(rid*edlen, (lld)edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
// #define DEBUG 0
#define forn(i,l,n) for(int i = l; i < n; i++)
#define sci(x) scanf("%d", &x)
#define scii(x,y) scanf("%d%d", &x, &y)
#define scld(x) scanf("%ld", &x)
#define sclld(x) scanf("%lld", &x)
#define pri(x) printf("%d", x)
#define prin(x) printf("%d\n", x)
#define prld(x) printf("%ld", x)
#define prldn(x) printf("%ld\n", x)
#define prlld(x) printf("%lld", x)
#define prlldn(x) printf("%lld\n", x)
#define prs(x) printf("%s", x)
#define prsn(x) printf("%s\n", x)
#define prin(x) printf("%d\n", x)
#define pi pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vpi vector<pi>
#define pb(x) push_back(x)
#define ld long
#define lld long long
#define miN(a,b) (a < b ? (a) : (b))
#define MAXN 200001

using namespace std;

int arr[MAXN];

typedef struct rangeStruct {
    int st;
    int ed;
    int val;
} Range;

vector<Range> vr;

int main()
{
    // freopen("input.txt", "r", stdin);
    int n;
    ll k;
    cin >> n;
    cin >> k;

    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    sort(arr, arr+n);

    int cur = -1;
    for(int i = 0; i < n; i++)
    {
        if(arr[i] != cur)
        {
            if(!vr.empty())
            {
                vr[vr.size()-1].ed = i-1;
            }
            Range r;
            r.st = i;
            r.val = arr[i];
            cur = arr[i];
            vr.pb(r);
        }
    }

    vr[vr.size() - 1].ed = n-1;

    int st = 0;
    int ed = vr.size() - 1;
    while(k > 0)
    {
        int stlen = vr[st].ed - vr[st].st + 1;
        int edlen = vr[ed].ed - vr[ed].st + 1;

        if(stlen <= edlen)
        {
            // cout << "Stlen is smaller" << endl;
            if(k >= stlen)
            {
                lld rid = k / stlen;
                k -= miN(rid*stlen, (lld)stlen*(vr[st+1].val - vr[st].val));
                vr[st].val += miN(rid, vr[st+1].val-vr[st].val);
                // cout << "Value at " << st << " is now " << vr[st].val << endl;
                // cout << "K = " << k << endl;
                if(vr[st].val == vr[st+1].val)
                {
                    // cout << "Increasing st " << endl;
                    vr[st+1].st = vr[st].st;
                    st++;
                }
            }
            else
            {
                break;
            }

        }
        else if(stlen > edlen)
        {
            if(k >= edlen)
            {
                lld rid = k / edlen;
                k -= miN(rid*edlen, (lld)edlen*(vr[ed].val - vr[ed-1].val));
                vr[ed].val -= miN(rid, vr[ed].val - vr[ed-1].val);
                if(vr[ed].val == vr[ed-1].val)
                {
                    vr[ed-1].ed = vr[ed].ed;
                    ed--;
                }
            }
            else
            {
                break;
            }

        }

        if(vr[st].val == vr[ed].val) break;
    }
    // cout << "Vr[Ed] " << vr[ed].val << " Vr[St] " << vr[st].val << endl;
    // cout << "St " << st << " Ed " << ed << endl;
    cout << vr[ed].val - vr[st].val << endl;

    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,k,a[100005],sf[1000005],se[100005],l,r,R,d,l1,r1,mid,ind,idx,mx,ans;
 main() {
	cin>>n>>p;
	for(k=1; k<=n; k++)
		cin>>a[k];
	sort(a+1,a+n+1);
	for(k=1; k<=n; k++) {
		sf[k]=sf[k-1]+a[k];
	}

	for(k=n; k>=1; k--) {
		se[k]=se[k+1]+a[k];
	}
	ans=1e9;

	for(k=1; k<=n; k++) {

		d=a[k]*k-sf[k];
		if(p<d)  break;
		R=p-d;

		l=a[k];
		r=a[n];

		while(l<=r) {

			mid=(l+r)/2;

			l1=k;
			r1=n;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]>=mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=se[idx]-mid*(n-idx+1);
			if(x<=R) {
				r=mid-1;
				mx=mid;
			}
			else {
				l=mid+1;
			}
		}
		ans=min(ans,mx-a[k]);

	}
	for(k=1; k<=n; k++) {

		d=se[k]-a[k]*(n-k+1);
		if(p<d)  break;
		R=p-d;

		l=1;
		r=a[k];

		while(l<=r) {

			mid=(l+r)/2;

			l1=1;
			r1=k;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]<mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=mid*k-sf[idx];
			if(x<=R) {
				l=mid+1;
				mx=mid;
			} else {
				r=mid-1;
			}
		}
		ans=min(ans,a[k]-mx);

	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,k,a[100005],sf[1000005],se[100005],l,r,R,d,l1,r1,mid,ind,idx,mx,ans;
 main() {
	cin>>n>>p;
	for(k=1; k<=n; k++)
		cin>>a[k];
	sort(a+1,a+n+1);
	for(k=1; k<=n; k++) {
		sf[k]=sf[k-1]+a[k];
	}

	for(k=n; k>=1; k--) {
		se[k]=se[k+1]+a[k];
	}
	ans=1e9;

	for(k=1; k<=n; k++) {

		d=a[k]*k-sf[k];
		if(p<d)  break;
		R=p-d;

		l=a[k];
		r=a[n];

		while(l<=r) {

			mid=(l+r)/2;

			l1=k;
			r1=n;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]>=mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=se[idx]-mid*(n-idx+1);
			if(x<=R) {
				r=mid-1;
				mx=mid;
			}
			else {
				l=mid+1;
			}
		}
		ans=min(ans,mx-a[k]);

	} /*
	for(k=1; k<=n; k++) {

		d=se[k]-a[k]*(n-k+1);
		if(p<d)  break;
		R=p-d;

		l=1;
		r=a[k];

		while(l<=r) {

			mid=(l+r)/2;

			l1=1;
			r1=k;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]<mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=mid*k-sf[idx];
			if(x<=R) {
				l=mid+1;
				mx=mid;
			} else {
				r=mid-1;
			}
		}
		ans=min(ans,a[k]-mx);

	}*/
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,k,a[100005],sf[1000005],se[100005],l,r,R,d,l1,r1,mid,ind,idx,mx,ans;
 main() {
	cin>>n>>p;
	for(k=1; k<=n; k++)
		cin>>a[k];
	sort(a+1,a+n+1);
	for(k=1; k<=n; k++) {
		sf[k]=sf[k-1]+a[k];
	}

	for(k=n; k>=1; k--) {
		se[k]=se[k+1]+a[k];
	}
	ans=1e9;

	for(k=1; k<=n; k++) {

		d=a[k]*k-sf[k];
		if(p<d)  break;
		R=p-d;

		l=a[k];
		r=a[n];

		while(l<=r) {

			mid=(l+r)/2;

			l1=k;
			r1=n;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]>=mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=se[idx]-mid*(n-idx+1);
			if(x<=R) {
				r=mid-1;
				mx=mid;
			}
			else {
				l=mid+1;
			}
		}
		ans=min(ans,mx-a[k]);

	}
	for(k=1; k<=n; k++) {

		d=se[k]-a[k]*(n-k+1);
		if(p<d)  break;
		R=p-d;

		l=1;
		r=a[k];

		while(l<=r) {

			mid=(l+r)/2;

			l1=1;
			r1=k;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]<=mid) {
					l1=ind+1;
					idx=ind;
				} else r1=ind-1;
			}
			int x=mid*k-sf[idx];
			if(x<=R) {
				l=mid+1;
				mx=mid;
			} else {
				r=mid-1;
			}
		}
		ans=min(ans,a[k]-mx);

	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,k,a[100005],sf[1000005],se[100005],l,r,R,d,l1,r1,mid,ind,idx,mx,ans;
 main() {
	cin>>n>>p;
	for(k=1; k<=n; k++)
		cin>>a[k];
	sort(a+1,a+n+1);
	for(k=1; k<=n; k++) {
		sf[k]=sf[k-1]+a[k];
	}

	for(k=n; k>=1; k--) {
		se[k]=se[k+1]+a[k];
	}
	ans=1e9;

	for(k=1; k<=n; k++) {

		d=a[k]*k-sf[k];
		if(p<d)  break;
		R=p-d;

		l=a[k];
		r=a[n];

		while(l<=r) {

			mid=(l+r)/2;

			l1=k;
			r1=n;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]>=mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=se[idx]-mid*(n-idx+1);
			if(x<=R) {
				r=mid-1;
				mx=mid;
			}
			else {
				l=mid+1;
			}
		}
		ans=min(ans,mx-a[k]);

	}
	for(k=n; k>=1; k--) {

		d=se[k]-a[k]*(n-k+1);
		if(p<d)  break;
		R=p-d;

		l=1;
		r=a[k];

		while(l<=r) {

			mid=(l+r)/2;

			l1=1;
			r1=k;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]<=mid) {
					l1=ind+1;
					idx=ind;
				} else r1=ind-1;
			}
			int x=mid*k-sf[idx];
			if(x<=R) {
				l=mid+1;
				mx=mid;
			} else {
				r=mid-1;
			}
		}
		ans=min(ans,a[k]-mx);

	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,k,a[100005],sf[1000005],se[100005],l,r,R,d,l1,r1,mid,ind,idx,mx,ans;
 main() {
	cin>>n>>p;
	for(k=1; k<=n; k++)
		cin>>a[k];
	sort(a+1,a+n+1);
	for(k=1; k<=n; k++) {
		sf[k]=sf[k-1]+a[k];
	}

	for(k=n; k>=1; k--) {
		se[k]=se[k+1]+a[k];
	}
	ans=1e9;

	for(k=1; k<=n; k++) {

		d=a[k]*k-sf[k];
		if(p<d)  break;
		R=p-d;

		l=a[k];
		r=a[n];

		while(l<=r) {

			mid=(l+r)/2;

			l1=k;
			r1=n;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]>=mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=se[idx]-mid*(n-idx+1);
			if(x<=R) {
				r=mid-1;
				mx=mid;
			}
			else {
				l=mid+1;
			}
		}
		ans=min(ans,mx-a[k]);

	}
	for(k=n; k>=1; k--) {

		d=se[k]-a[k]*(n-k+1);
		if(p<d)  break;
		R=p-d;

		l=a[1];
		r=a[k];

		while(l<=r) {

			mid=(l+r)/2;

			l1=1;
			r1=k;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]<=mid) {
					l1=ind+1;
					idx=ind;
				} else r1=ind-1;
			}
			int x=mid*idx-sf[idx];
			if(x<=R) {
				l=mid+1;
				mx=mid;
			} else {
				r=mid-1;
			}
		}
		ans=min(ans,a[k]-mx);

	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,k,a[100005],sf[1000005],se[100005],l,r,R,d,l1,r1,mid,ind,idx,mx,ans;
 main() {
	cin>>n>>p;
	for(k=1; k<=n; k++)
		cin>>a[k];
	sort(a+1,a+n+1);
	for(k=1; k<=n; k++) {
		sf[k]=sf[k-1]+a[k];
	}

	for(k=n; k>=1; k--) {
		se[k]=se[k+1]+a[k];
	}
	ans=1e9;
	for(k=1; k<=n; k++) {

		d=a[k]*k-sf[k]; //cout<<d<<endl;
		if(p<d)  break;
		R=p-d;

		l=a[k];
		r=a[n];

		while(l<=r) {

			mid=(l+r)/2;

			l1=k;
			r1=n;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]>mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=se[idx]-mid*(n-idx+1);
			if(x<=R) {
				r=mid-1;
				mx=mid;
			} else {
				l=mid+1;
			}
		}
		ans=min(ans,mx-a[k]);

	}
	for(k=1; k<=n; k++) {

		d=se[k]-a[k]*(n-k+1);
		if(p<d)  break;
		R=p-d;

		l=1;
		r=a[k];

		while(l<=r) {

			mid=(l+r)/2;

			l1=1;
			r1=k;
			while(l1<=r1) {
				ind=(l1+r1)/2;

				if(a[ind]<mid) {
					r1=ind-1;
					idx=ind;
				} else l1=ind+1;
			}
			int x=mid*k-sf[idx];
			if(x<=R) {
				r=mid-1;
				mx=mid;
			} else {
				l=mid+1;
			}
		}
		ans=min(ans,a[k]-mx);

	}
	cout<<ans<<endl;
}