///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

LL N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    for(int i=1; i<=N; i++) {
        LL L = A[i];
        LL indxL = i-1;
        LL sumL = S[i-1];
        LL costL = (L*indxL) - sumL;

        LL R = L+m;
        vector<LL>::iterator it = upper_bound(V.begin(), V.end(), R);
        it--;
        LL indxR = it - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-indxR-1));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    if(f(ret-1)) {
        cout << ret-1 << "\n";
    }
    else {
        cout << ret << "\n";
    }

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

int N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    //cout << "m = " << m << endl << endl;
    for(int i=1; i<=N; i++) {
        //cout << "i = " << i << "\n\n";
        LL L = A[i];
        LL indxL = i-1;
        LL sumL = S[i-1];
        LL costL = (L*indxL) - sumL;

        //cout << "L = " << L << ", indxL = " << indxL << ", sumL = " << sumL << ", costL = " << costL << endl;

        LL x = L+m;
        //cout << "x = " << x << endl;
        vector<LL>::iterator it = upper_bound(V.begin(), V.end(), x);
        it--;
        LL indxR = it - V.begin();
        LL R = x;
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-indxR-1));

        //cout << "S[N] = " << S[N] << ", S[indxR+1] = " << S[indxR+1] << endl;

        //cout << "N = " << N << ", indxR = " << indxR << ", N-indxR-1 = " << N-indxR-1 << ", R*(N-indxR-1) = " << (R*(N-indxR-1)) << endl;

        //cout << "R = " << R << ", indxR = " << indxR << ", sumR = " << sumR << ", costR = " << costR << endl;

        LL totCost = costL + costR;

        //cout << "costL = " << costL << ", costR = " << costR << ", totCost = " << totCost << endl;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N-1]-A[0], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    cout << ret << "\n";

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    return 0;
}


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

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define LL long long

#define SIZE 100005

LL N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    for(int i=1; i<=N; i++) {
        LL L = A[i];
        vector<LL>::iterator it1 = lower_bound(V.begin(), V.end(), L);
        LL indxL = it1 - V.begin();
        LL sumL = S[indxL];
        LL costL = (L*indxL) - sumL;

        LL R = L+m;
        vector<LL>::iterator it2 = upper_bound(V.begin(), V.end(), R);
        it2--;
        LL indxR = it2 - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-1-indxR));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    for(int i=1; i<=N; i++) {
        LL L = max((LL)0, A[i]-m);
        vector<LL>::iterator it1 = lower_bound(V.begin(), V.end(), L);
        LL indxL = it1 - V.begin();
        LL sumL = S[indxL];
        LL costL = (L*indxL) - sumL;

        LL R = A[i];
        vector<LL>::iterator it2 = upper_bound(V.begin(), V.end(), R);
        it2--;
        LL indxR = it2 - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-1-indxR));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    if(ret>0 && f(ret-1)) {
        cout << ret-1 << "\n";
    }
    else {
        cout << ret << "\n";
    }

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

LL A[SIZE];

LL n, k;

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

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

    sort(A, A+n);

    LL low = 0, high = A[n-1]-A[0], ret = high;
    while(low<=high) {
        LL mid = (low+high)>>1;

        int L = 0, R = n-1;
        LL cnt = 0;
        while(L<R) {
            LL diff = A[R] - A[L];
            if(diff>mid) {
                cnt += (diff-mid);
            }
            L++;
            R--;
        }

        if(cnt<=k) {
            ret = mid;
            high = mid-1;
        }
        else {
            low = mid+1;
        }
    }

    cout << ret << "\n";

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

int N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    //cout << "m = " << m << endl << endl;
    for(int i=1; i<=N; i++) {
        //cout << "i = " << i << "\n\n";
        LL L = A[i];
        LL indxL = i-1;
        LL sumL = S[i-1];
        LL costL = (L*indxL) - sumL;

        //cout << "L = " << L << ", indxL = " << indxL << ", sumL = " << sumL << ", costL = " << costL << endl;

        LL x = L+m;
        //cout << "x = " << x << endl;
        vector<LL>::iterator it = upper_bound(V.begin(), V.end(), x);
        it--;
        LL indxR = it - V.begin();
        LL R = x;
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-indxR-1));

        //cout << "S[N] = " << S[N] << ", S[indxR+1] = " << S[indxR+1] << endl;

        //cout << "N = " << N << ", indxR = " << indxR << ", N-indxR-1 = " << N-indxR-1 << ", R*(N-indxR-1) = " << (R*(N-indxR-1)) << endl;

        //cout << "R = " << R << ", indxR = " << indxR << ", sumR = " << sumR << ", costR = " << costR << endl;

        LL totCost = costL + costR;

        //cout << "costL = " << costL << ", costR = " << costR << ", totCost = " << totCost << endl;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    cout << ret << "\n";

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

LL N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    for(int i=1; i<=N; i++) {
        LL L = A[i];
        LL indxL = i-1;
        LL sumL = S[i-1];
        LL costL = (L*indxL) - sumL;

        LL R = L+m;
        vector<LL>::iterator it = upper_bound(V.begin(), V.end(), R);
        it--;
        LL indxR = it - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-indxR-1));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    if(f(ret-1) && ret>0) {
        cout << ret-1 << "\n";
    }
    else {
        cout << ret << "\n";
    }

    return 0;
}


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

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define LL long long

#define SIZE 100005

LL N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    for(int i=1; i<=N; i++) {
        LL L = A[i];
        vector<LL>::iterator it1 = lower_bound(V.begin(), V.end(), L);
        LL indxL = it1 - V.begin();
        LL sumL = S[indxL];
        LL costL = (L*indxL) - sumL;

        LL R = L+m;
        vector<LL>::iterator it2 = upper_bound(V.begin(), V.end(), R);
        it2--;
        LL indxR = it2 - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-1-indxR));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    if(ret>0 && f(ret-1)) {
        cout << ret-1 << "\n";
    }
    else {
        cout << ret << "\n";
    }

    return 0;
}


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

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define LL long long

#define SIZE 100005

LL N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    for(int i=1; i<=N; i++) {
        LL L = A[i];
        vector<LL>::iterator it1 = lower_bound(V.begin(), V.end(), L);
        LL indxL = it1 - V.begin();
        LL sumL = S[indxL];
        LL costL = (L*indxL) - sumL;

        LL R = L+m;
        vector<LL>::iterator it2 = upper_bound(V.begin(), V.end(), R);
        it2--;
        LL indxR = it2 - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-1-indxR));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    for(int i=1; i<=N; i++) {
        LL L = max((LL)0, A[i]-m);
        vector<LL>::iterator it1 = lower_bound(V.begin(), V.end(), L);
        LL indxL = it1 - V.begin();
        LL sumL = S[indxL];
        LL costL = (L*indxL) - sumL;

        LL R = A[i];
        vector<LL>::iterator it2 = upper_bound(V.begin(), V.end(), R);
        it2--;
        LL indxR = it2 - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-1-indxR));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)>>1;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    if(ret>0 && f(ret-1)) {
        cout << ret-1 << "\n";
    }
    else {
        cout << ret << "\n";
    }

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

int N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    //cout << "m = " << m << endl << endl;
    for(int i=1; i<=N; i++) {
        //cout << "i = " << i << "\n\n";
        LL L = A[i];
        LL indxL = i-1;
        LL sumL = S[i-1];
        LL costL = (L*indxL) - sumL;

        //cout << "L = " << L << ", indxL = " << indxL << ", sumL = " << sumL << ", costL = " << costL << endl;

        LL x = L+m;
        //cout << "x = " << x << endl;
        vector<LL>::iterator it = upper_bound(V.begin(), V.end(), x);
        it--;
        LL indxR = it - V.begin();
        LL R = A[indxR+1];
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-indxR-1));

        //cout << "S[N] = " << S[N] << ", S[indxR+1] = " << S[indxR+1] << endl;

        //cout << "N = " << N << ", indxR = " << indxR << ", N-indxR-1 = " << N-indxR-1 << ", R*(N-indxR-1) = " << (R*(N-indxR-1)) << endl;

        //cout << "R = " << R << ", indxR = " << indxR << ", sumR = " << sumR << ", costR = " << costR << endl;

        LL totCost = costL + costR;

        //cout << "costL = " << costL << ", costR = " << costR << ", totCost = " << totCost << endl;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N-1]-A[0], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    cout << ret << "\n";

    return 0;
}


///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#include <sys/resource.h>     // for linux stack memory increase
//#define gc getchar_unlocked   // for linux fast io
//#define gc getchar            // for windows fast io

#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define nl puts("")
#define sp printf(" ")
#define phl debug("Hello")
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((vlong)(x).size())
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define SQ(x) ((x)*(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define arrayIndexPrint(A,i) cerr<<"~ At pos: "<<i<<" = "<<A[i]
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define arrayPrint(A,st,ed) cerr<<"~ Array:";FOR(i,st,ed) cerr<<" "<<A[i];cerr<<endl
#define LINE cerr<<"\n"; FOR(i,0,50) cerr<<"=";cerr<<"\n\n"

#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;

#ifdef forthright48
     #include <ctime>
     clock_t tStart = clock();
     #define debug(args...) {dbg,args; cerr<<endl;}
     #define timeStamp debug ("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)
     #define bug printf("%d\n",__LINE__);

#else
    #define debug(args...)  // Just strip off all debug tokens
    #define timeStamp
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

vlong ext_gcd ( vlong A, vlong B, vlong *X, vlong *Y ){
    vlong x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline vlong modInv ( vlong a, vlong m ) {
    vlong x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline vlong bigmod ( vlong a, vlong p, vlong m ) {
    vlong res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

#define SIZE 100005

LL N, K;

vector<LL> V;

LL A[SIZE];
LL S[SIZE];

bool f(LL m) {
    for(int i=1; i<=N; i++) {
        LL L = A[i];
        LL indxL = i-1;
        LL sumL = S[i-1];
        LL costL = (L*indxL) - sumL;

        LL R = L+m;
        vector<LL>::iterator it = upper_bound(V.begin(), V.end(), R);
        it--;
        LL indxR = it - V.begin();
        LL sumR = S[N] - S[indxR+1];
        LL costR = sumR - (R*(N-indxR-1));

        LL totCost = costL + costR;

        if(totCost<=K) return true;
    }

    return false;
}

int main () {
    #ifdef forthright48
    freopen ( "input.txt", "r", stdin );
    //freopen ( "output.txt", "w", stdout );
    #endif // forthright48

    fast_cin;

    cin >> N >> K;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
        V.push_back(A[i]);
    }

    sort(A+1, A+N+1);
    sort(V.begin(), V.end());

    for(int i=1; i<=N; i++) {
        S[i] = S[i-1] + A[i];
    }

    LL low=0, high=A[N]-A[1], ret = high;

    while(low<=high) {
        LL mid = (low+high)/2;
        if(f(mid)) {
            ret = mid;
            high = mid-1;
        }
        else {
            low= mid+1;
        }
    }

    cout << ret << "\n";

    return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds;
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl;
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const mod = 1e9+7;
ll const inf = 1e14;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);}

// CODE STARTS HERE
bool check(ll n,ll k,ll val,std::vector<ll> &prefix,std::vector<ll> &v){
    for (ll i = 0; i < n; ++i)
    {
        ll m = upper_bound(v.begin(), v.end(),v[i] + val) - v.begin();

        ll sum = 0;
        if(m == 0)sum = prefix[n - 1] - v[i];
        else sum = prefix[n-1] - prefix[m - 1];

        ll cost = max(0ll,sum - (n - m) * (v[i] + val));
        if(i != 0) cost += max(0ll,v[i]*i - prefix[i-1]);

        if(cost <= k) return true;
    }
    for (ll i = n - 1 ; i >= 0; i--)
    {
        ll m = lower_bound(v.begin(), v.end(),v[i] - val) - v.begin();

        ll cost = max(0ll,(prefix[n - 1] - prefix[i]) - (n - i - 1ll)*(v[i]));
        if(m != 0) cost += max(0ll,(v[i] - val)*m - prefix[m - 1]);

        if(cost <= k) return true;
    }
    return false;
}

int main(){
    IOS

    ll n,k;cin >> n >> k;
    std::vector<ll> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    std::vector<ll> prefix(n + 1);
    for (int i = 0; i < n; ++i)
    {
        if(i == 0) prefix[i] = v[i];
        else prefix[i] = prefix[i - 1] + v[i];
    }
    ll low = 0;
    ll high = v[n-1] - v[0];
    ll ans = inf;
    while(low <= high){
        ll mid = (low + high) >> 1ll;
        if(check(n,k,mid,prefix,v)){
            ans = mid;
            high = mid - 1;
        }
        else{
            low = mid + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds;
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl;
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const mod = 1e9+7;
ll const inf = 1e14;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);}

// CODE STARTS HERE
bool check(ll n,ll k,ll val,std::vector<ll> &prefix,std::vector<ll> &v){
    for (ll i = 0; i < n; ++i)
    {
        ll m = upper_bound(v.begin(), v.end(),v[i] + val) - v.begin();

        ll sum = 0;
        if(m == 0)sum = prefix[n - 1] - v[i];
        else sum = prefix[n-1] - prefix[m - 1];

        ll cost = max(0ll,sum - (n - m) * (v[i] + val));
        if(i != 0) cost += max(0ll,v[i]*i - prefix[i-1]);

        if(cost <= k) return true;
    }
    for (ll i = n - 1 ; i >= 0; i--)
    {
        ll m = lower_bound(v.begin(), v.end(),v[i] - val) - v.begin();

        ll cost = max(0ll,(prefix[n - 1] - prefix[i]) - (n - i - 1ll)*(v[i]));
        if(m != 0) cost += max(0ll,(v[i] - val)*m - prefix[m - 1]);

        if(cost <= k) return true;
    }
    return false;
}

int main(){
    IOS

    ll n,k;cin >> n >> k;

    std::vector<ll> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    std::vector<ll> prefix(n + 1);
    for (int i = 0; i < n; ++i)
    {
        if(i == 0) prefix[i] = v[i];
        else prefix[i] = prefix[i - 1] + v[i];
    }

    ll low = 0;
    ll high = v[n-1] - v[0];
    ll ans = v[n-1] - v[0];
    while(low <= high){
        ll mid = (low + high) >> 1;

        if(check(n,k,mid,prefix,v)){
            ans = mid;
            high = mid - 1;
        }
        else low = mid + 1;

    }

    cout << ans << endl;

    return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds;
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl;
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const mod = 1e9+7;
ll const inf = 1e14;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);}

// CODE STARTS HERE
ll prefix[size_1d];
std::vector<ll> v;
bool check(int n,ll k,ll val){
    for (int i = 0; i < n; ++i)
    {
        auto m = upper_bound(v.begin(), v.end(),v[i] + val) - v.begin();
        watch(v[m])
        ll sum;
        if(m == 0){
            sum = prefix[n - 1] - v[i];
        }
        else
            sum = prefix[n-1] - prefix[m - 1];
        watch(sum)
        watch(m)
        ll cost = max(0ll,sum - (n - m) * (v[i] + val));
        if(i != 0){
            cost += v[i]*i - prefix[i-1];
        }
        watch(cost)
        watch(i)
        watch(val)
        if(cost <= k){
            return true;
        }
    }
    return false;
}

int main(){
    IOS

    ll n,k;cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
        for (int i = 0; i < n; ++i)
    {
        if(i == 0) prefix[i] = v[i];
        else prefix[i] = prefix[i - 1] + v[i];
    }
    ll low = 0;
    ll high = inf;
    ll ans = inf;
    while(low <= high){
        ll mid = (low + high) >> 1ll;
        if(check(n,k,mid)){
            ans = mid;
            high = mid - 1;
        }
        else{
            low = mid + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds;
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl;
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const mod = 1e9+7;
ll const inf = 1e14;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);}

// CODE STARTS HERE
ll prefix[size_1d];
std::vector<ll> v;
bool check(ll n,ll k,ll val){
    for (ll i = 0; i < n; ++i)
    {
        ll m = upper_bound(v.begin(), v.end(),v[i] + val) - v.begin();
        // watch(v[m])
        ll sum;
        if(m == 0){
            sum = prefix[n - 1] - v[i];
        }
        else
            sum = prefix[n-1] - prefix[m - 1];
        // watch(sum)
        // watch(m)
        ll cost = max(0ll,sum - (n - m) * (v[i] + val));
        if(i != 0){
            cost += max(0ll,v[i]*i - prefix[i-1]);
        }
        // watch(cost)
        // watch(i)
        // watch(val)
        if(cost <= k){
            return true;
        }
    }
    return false;
}

int main(){
    IOS

    ll n,k;cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
        for (int i = 0; i < n; ++i)
    {
        if(i == 0) prefix[i] = v[i];
        else prefix[i] = prefix[i - 1] + v[i];
    }
    ll low = 0;
    ll high = inf;
    ll ans = inf;
    while(low <= high){
        ll mid = (low + high) >> 1ll;
        if(check(n,k,mid)){
            ans = mid;
            high = mid - 1;
        }
        else{
            low = mid + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds;
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl;
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const mod = 1e9+7;
ll const inf = 1e14;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);}

// CODE STARTS HERE
ll prefix[size_1d];
std::vector<ll> v;
bool check(ll n,ll k,ll val){
    for (ll i = 0; i < n; ++i)
    {
        ll m = upper_bound(v.begin(), v.end(),v[i] + val) - v.begin();
        // watch(v[m])
        ll sum = 0;
        if(m == 0)
            sum = prefix[n - 1] - v[i];
        else
            sum = prefix[n-1] - prefix[m - 1];
        // watch(sum)
        // watch(m)
        ll cost = max(0ll,sum - (n - m) * (v[i] + val));
        if(i != 0){
            cost += max(0ll,v[i]*i - prefix[i-1]);
        }
        // watch(cost)
        // watch(i)
        // watch(val)
        if(cost <= k){
            return true;
        }
    }
    for (ll i = n - 1 ; i >= 0; i--)
    {
    	ll m = lower_bound(v.begin(), v.end(),v[i] - val) - v.begin();
        ll cost = max(0ll,(prefix[n - 1] - prefix[i]) - (n - i - 1ll)*(v[i]));
        if(m != 0)
        	cost += max(0ll,(v[i] - val)*m - prefix[m - 1]);
    	if(cost <= k)
    		return true;
    }
    return false;
}

int main(){
    IOS

    ll n,k;cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; ++i)
    {
        if(i == 0) prefix[i] = v[i];
        else prefix[i] = prefix[i - 1] + v[i];
    }
    ll low = 0;
    ll high = inf;
    ll ans = inf;
    while(low <= high){
        ll mid = (low + high) >> 1ll;
        if(check(n,k,mid)){
            ans = mid;
            high = mid - 1;
        }
        else{
            low = mid + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds;
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl;
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const mod = 1e9+7;
ll const inf = 1e14;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);}

// CODE STARTS HERE
ll prefix[size_1d];
std::vector<ll> v;
bool check(int n,ll k,ll val){
    for (int i = 0; i < n; ++i)
    {
        auto m = upper_bound(v.begin(), v.end(),v[i] + val) - v.begin();
        // watch(v[m])
        ll sum;
        if(m == 0){
            sum = prefix[n - 1] - v[i];
        }
        else
            sum = prefix[n-1] - prefix[m - 1];
        // watch(sum)
        // watch(m)
        ll cost = max(0ll,sum - (n - m) * (v[i] + val));
        if(i != 0){
            cost += v[i]*i - prefix[i-1];
        }
        // watch(cost)
        // watch(i)
        // watch(val)
        if(cost <= k){
            return true;
        }
    }
    return false;
}

int main(){
    IOS

    ll n,k;cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
        for (int i = 0; i < n; ++i)
    {
        if(i == 0) prefix[i] = v[i];
        else prefix[i] = prefix[i - 1] + v[i];
    }
    ll low = 0;
    ll high = inf;
    ll ans = inf;
    while(low <= high){
        ll mid = (low + high) >> 1ll;
        if(check(n,k,mid)){
            ans = mid;
            high = mid - 1;
        }
        else{
            low = mid + 1;
        }
    }
    cout << ans << endl;

    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
vector < ll > v;
ll k;
bool can (ll lo, ll hi) {
    ll op = 0;
    for (ll i = 0; i < v.size(); i++) {
        if (v[i] < lo) op += lo - v[i];
        if (v[i] > hi) op += v[i] - hi;
    }
    //cout << lo << " " << hi << " " << op << endl;
    return op <= k;
}
pll getlohi (ll avg) {
    ll l1 = 0, h1 = avg, l2 = avg, h2 = oo;
    while (l1 < h1 || l2 < h2) {
        ll mid1 = (h1 + l1 + 1) / 2, mid2 = (h2 + l2) / 2;
        //cout << l1 << " " << h1 << " " << l2 << " " << h2 << " " << mid1 << " " << mid2 << endl;
        if (can(mid1, mid2)) {
            if (l1 < h1) l1 = mid1;
            if (l2 < h2) h2 = mid2;
        }
        else {
            if (l1 < h1) h1 = mid1 - 1;
            if (l2 < h2) l2 = mid2 + 1;
        }
    }
    pll ret = make_pair(l1, h2);
    return ret;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, avg = 0;
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
        avg += x;
    }
    // avg = 0;
    avg /= n;
    pll p1 = getlohi(avg), p2 = getlohi(avg + 1);
    cout << min((p1.second - p1.first), (p2.second - p2.first)) << endl;
    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;

ll csm[M], rcsm[M];
vector < ll > v;
ll n, k;
ll getop (ll lo, ll hi) {
    //cout << lo << " " << hi << " " <<  "ok" << endl;
    ll a = upper_bound(v.begin(), v.end(), lo) - v.begin();
    ll b = lower_bound(v.begin(), v.end(), hi) - v.begin();
    ll op = a * lo - (a > 0) ? csm[a - 1] : 0;
    //cout << op << endl;
    op += rcsm[b] - hi * (n - b);
    //cout << lo << " " << hi << " " <<  op << endl;
    return op;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    csm[0] = v[0]; rcsm[n - 1] = v[n - 1];
    for (ll i = 1; i < v.size(); i++) csm[i] = csm[i - 1] + v[i];
    for (ll i = n - 2; i >= 0; i--) rcsm[i] = rcsm[i + 1] + v[i];
    ll ans = oo;
    for (int i = n - 1; i >= 0; i--) {
        ll hi = v[i], lo = 0;
        while (lo < hi) {
            ll mid = (lo + hi + 1) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                lo = mid;
                ans = min(ans, v[i] - lo);
            }
            else hi = mid - 1;
        }
    }
    for (int i = 0; i < n; i++) {
        ll hi = oo, lo = v[i];
        while (lo < hi) {
            ll mid = (lo + hi) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                hi = mid;
                ans = min(ans, hi - v[i]);
            }
            else lo = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;

ll csm[M], rcsm[M];
vector < ll > v;
ll n, k;
ll getop (ll lo, ll hi) {
    //cout << lo << " " << hi << " " <<  "ok" << endl;
    ll a = upper_bound(v.begin(), v.end(), lo) - v.begin();
    ll b = lower_bound(v.begin(), v.end(), hi) - v.begin();
    ll op = a * lo - csm[a - 1];
    //cout << op << endl;
    op += rcsm[b] - hi * (n - b);
    //cout << lo << " " << hi << " " <<  op << endl;
    return op;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    csm[0] = v[0]; rcsm[n - 1] = v[n - 1];
    for (ll i = 1; i < v.size(); i++) csm[i] = csm[i - 1] + v[i];
    for (ll i = n - 2; i >= 0; i--) rcsm[i] = rcsm[i + 1] + v[i];
    ll ans = oo;
    for (int i = n - 1; i >= 0; i--) {
        ll hi = v[i], lo = 0;
        while (lo < hi) {
            ll mid = (lo + hi + 1) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                lo = mid;
                ans = min(ans, v[i] - lo);
            }
            else hi = mid - 1;
        }
    }
    for (int i = 0; i < n; i++) {
        ll hi = oo, lo = v[i];
        while (lo < hi) {
            ll mid = (lo + hi) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                hi = mid;
                ans = min(ans, hi - v[i]);
            }
            else lo = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
vector < ll > v;
ll k;
bool can (ll lo, ll hi) {
    ll op = 0;
    for (ll i = 0; i < v.size(); i++) {
        if (v[i] < lo) op += lo - v[i];
        if (v[i] > hi) op += v[i] - hi;
    }
    //cout << lo << " " << hi << " " << op << endl;
    return op <= k;
}
pll getlohi (ll avg) {
    ll l1 = avg - oo, h1 = avg, l2 = avg, h2 = avg + oo, mid1 = 0, mid2 = 0;
    while (l1 < h1 && l2 < h2) {
        mid1 = (h1 + l1 + 1) / 2, mid2 = (h2 + l2) / 2;

        if (can(mid1, mid2)) {
            if (l1 < h1) l1 = mid1;
            if (l2 < h2) h2 = mid2;
        }
        else {
            if (l1 < h1) h1 = mid1 - 1;
            if (l2 < h2) l2 = mid2 + 1;
        }
        //cout << l1 << " " << h1 << " " << l2 << " " << h2 << " " << mid1 << " " << mid2 << endl;
    }
    pll ret = make_pair(l1, h2);
    return ret;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, avg = 0;
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
        avg += x;
    }
    // avg = 0;
    avg /= n;
    pll p1 = getlohi(avg), p2 = getlohi(avg + 1);
    cout << min((p1.second - p1.first), (p2.second - p2.first)) << endl;
    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
vector < ll > v;
ll k;
bool can (ll lo, ll hi) {
    ll op = 0;
    for (ll i = 0; i < v.size(); i++) {
        if (v[i] < lo) op += lo - v[i];
        if (v[i] > hi) op += v[i] - hi;
    }
    //cout << lo << " " << hi << " " << op << endl;
    return op <= k;
}
pll getlohi (ll avg) {
    ll l1 = 0, h1 = avg, l2 = avg, h2 = oo;
    while (l1 < h1 || l2 < h2) {
        ll mid1 = (h1 + l1 + 1) / 2, mid2 = (h2 + l2) / 2;
        //cout << l1 << " " << h1 << " " << l2 << " " << h2 << " " << mid1 << " " << mid2 << endl;
        if (can(mid1, mid2)) {
            if (l1 < h1) l1 = mid1;
            if (l2 < h2) h2 = mid2;
        }
        else {
            if (l1 < h1) h1 = mid1 - 1;
            if (l2 < h2) l2 = mid2 + 1;
        }
    }
    pll ret = make_pair(l1, h2);
    return ret;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, avg;
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
        avg += x;
    }
    // avg = 0;
    avg /= n;
    pll p1 = getlohi(avg), p2 = getlohi(avg + 1);
    cout << min((p1.second - p1.first), (p2.second - p2.first)) << endl;
    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;

ll csm[M], rcsm[M];
vector < ll > v;
ll n, k;
ll getop (ll lo, ll hi) {
    //cout << lo << " " << hi << " " <<  "ok" << endl;
    ll a = upper_bound(v.begin(), v.end(), lo) - v.begin();
    ll b = lower_bound(v.begin(), v.end(), hi) - v.begin();
    ll op = a * lo - ((a > 0) ? csm[a - 1] : 0);
    //cout << op << endl;
    op += rcsm[b] - hi * (n - b);
    //cout << lo << " " << hi << " " <<  op << endl;
    return op;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    csm[0] = v[0]; rcsm[n - 1] = v[n - 1];
    for (ll i = 1; i < v.size(); i++) csm[i] = csm[i - 1] + v[i];
    for (ll i = n - 2; i >= 0; i--) rcsm[i] = rcsm[i + 1] + v[i];
    ll ans = oo;
    for (int i = n - 1; i >= 0; i--) {
        ll hi = v[i], lo = 0;
        while (lo < hi) {
            ll mid = (lo + hi + 1) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                lo = mid;
                ans = min(ans, v[i] - lo);
            }
            else hi = mid - 1;
        }
    }
    for (int i = 0; i < n; i++) {
        ll hi = v[n - 1], lo = v[i];
        while (lo < hi) {
            ll mid = (lo + hi) / 2;
            ll op = getop(v[i], mid);
            if (op <= k) {
                hi = mid;
                ans = min(ans, hi - v[i]);
            }
            else lo = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


// Hope is a good thing maybe the best of things and no good thing ever dies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0)
#define testcase ll T; cin >> T; for (int tc = 1; tc <= T; tc++)
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;

ll csm[M], rcsm[M];
vector < ll > v;
ll n, k;
ll getop (ll lo, ll hi) {
    //cout << lo << " " << hi << " " <<  "ok" << endl;
    ll a = upper_bound(v.begin(), v.end(), lo) - v.begin();
    ll b = lower_bound(v.begin(), v.end(), hi) - v.begin();
    ll op = a * lo - ((a > 0) ? csm[a - 1] : 0);
    //cout << op << endl;
    op += rcsm[b] - hi * (n - b);
    //cout << lo << " " << hi << " " <<  op << endl;
    return op;
}
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    csm[0] = v[0]; rcsm[n - 1] = v[n - 1];
    for (ll i = 1; i < v.size(); i++) csm[i] = csm[i - 1] + v[i];
    for (ll i = n - 2; i >= 0; i--) rcsm[i] = rcsm[i + 1] + v[i];
    ll ans = oo;
    for (int i = n - 1; i >= 0; i--) {
        ll hi = v[i], lo = 0;
        while (lo < hi) {
            ll mid = (lo + hi + 1) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                lo = mid;
                ans = min(ans, v[i] - lo);
            }
            else hi = mid - 1;
        }
    }
    for (int i = 0; i < n; i++) {
        ll hi = oo, lo = v[i];
        while (lo < hi) {
            ll mid = (lo + hi) / 2;
            ll op = getop(mid, v[i]);
            if (op <= k) {
                hi = mid;
                ans = min(ans, hi - v[i]);
            }
            else lo = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define ll long long
using namespace std;
main()
{
	ll n,k,a,b,x,i;
	map<ll,ll>M;
	deque<pair<ll,ll> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));//cout<<it->first<<' '<<it->second<<'\n';
	}
	while(D.size()>1){
		ll y=(D[1].first - D[0].first); a= D[0].second;
		x=D.size()-1;
		ll z=(D[x].first - D[x-1].first); b= D[x].second;
		if(a<b){
			if(k>=a*y){
				k-=a*y;
				ll u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
			}
			else if(D[0].second<=k){
				k-=D[0].second;
				D[0].first++;
			}
		}
		else{
			if(k>=b*z){
				k-=b*z;
				ll u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
			}
			else if(D[x].second<=k){
				k-=D[x].second;
				D[x].first--;
			}
		}
		if(k<D[0].second && k<D[x].second) break;
	}
	if(D.size()<=1) cout<<"0\n";
	else{
		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
		//cout<<D[D.size()-1].first<<' '<<D[0].first;
	}
}


#include<bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define ll long long
using namespace std;
main()
{
	ll n,k,a,b,x,i;
	map<ll,ll>M;
	deque<pair<ll,ll> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));//cout<<it->first<<' '<<it->second<<'\n';
	}
	while(D.size()>1){
		ll y=(D[1].first - D[0].first); a= D[0].second;
		x=D.size()-1;
		ll z=(D[x].first - D[x-1].first); b= D[x].second;
		if(a<b){
			if(k>=a*y){
				k-=a*y;
				ll u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
			}
			else if(D[0].second<=k){
				ll u=k/a;
					k-=u*a;
					D[0].first+=u;
			}
		}
		else{
			if(k>=b*z){
				k-=b*z;
				ll u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
			}
			else if(D[x].second<=k){
				ll u=k/b;
				k-=u*b;
				D[x].first-=u;
			}
		}
		if(k<D[0].second && k<D[x].second) break;
	}

		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
		//cout<<D[D.size()-1].first<<' '<<D[0].first;

}


#include<bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define ll long long
using namespace std;
main()
{
	ll n,k,a,b,x,i;
	map<ll,ll>M;
	deque<pair<ll,ll> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));//cout<<it->first<<' '<<it->second<<'\n';
	}
	while(D.size()>1){
		ll y=(D[1].first - D[0].first); a= D[0].second;
		x=D.size()-1;
		ll z=(D[x].first - D[x-1].first); b= D[x].second;
		if(a<b){
			if(k>=a*y){
				k-=a*y;
				ll u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
			}
			else if(D[0].second<=k){
				ll u=k/a;

					k-=u*a;
					D[0].first+=u;

			}
		}
		else{
			if(k>=b*z){
				k-=b*z;
				ll u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
			}
			else if(D[x].second<=k){
				ll u=k/b;
				k-=u*b;
				D[x].first-=u;
			}
		}
		if(k<D[0].second || k<D[x].second) break;
	}

		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
		//cout<<D[D.size()-1].first<<' '<<D[0].first;

}


#include<bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
using namespace std;
main()
{
	int n,k,a,b,x,i;
	map<int,int>M;
	deque<pair<int,int> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));
	}
	while(D.size()>1){
		a=(D[1].first - D[0].first) * D[0].second;
		x=D.size()-1;
		b=(D[x].first - D[x-1].first) * D[x].second;
		if(a<b){
			if(k>=a){
				k-=a;
				int u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
			}
			else if(D[0].second<=k){
				k-=D[0].second;
				D[0].first++;
			}
		}
		else{
			if(k>=b){
				k-=b;
				int u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
			}
			else if(D[x].second<=k){
				k-=D[x].second;
				D[x].first--;
			}
		}
		if(k<D[0].second && k<D[x].second) break;
	}
	if(D.size()<=1) cout<<"0\n";
	else{
		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
	}
}


#include<bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
using namespace std;
main()
{
	int n,k,a,b,x,i;
	map<int,int>M;
	deque<pair<int,int> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));
	}
	while(D.size()>1){
		a=(D[1].first - D[0].first) * D[0].second;
		x=D.size()-1;
		b=(D[x].first - D[x-1].first) * D[x].second;
		if(a<b){
			if(k>=a){
				k-=a;
				int u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
			}
			else if(D[0].second<=k){
				k-=D[0].second;
				D[0].first++;
			}
		}
		else{
			if(k>=b){
				k-=b;
				int u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
			}
			else if(D[x].second<=k){
				k-=D[x].second;
				D[x].first++;
			}
		}
		if(k<D[0].second && k<D[x].second) break;
	}
	if(D.size()<=1) cout<<"0\n";
	else{
		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
	}
}


#include<bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define ll long long
using namespace std;
main()
{
	ll n,k,a,b,x,i;
	map<ll,ll>M;
	deque<pair<ll,ll> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));//cout<<it->first<<' '<<it->second<<'\n';
	}
	while(D.size()>1){
		ll y=(D[1].first - D[0].first); a= D[0].second;
		x=D.size()-1;
		ll z=(D[x].first - D[x-1].first); b= D[x].second;
		if(a<b){
			if(k>=a*y){
				k-=a*y;
				ll u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
			}
			else if(D[0].second<=k){
				if(k<=y){
				k-=a*y;
				ll u=D[1].first, v=D[0].second + D[1].second;
				D.pof();D.pof();
				D.puf(mp(u,v));
				}
				else{

				k-=D[0].second;
				D[0].first++;
			}
			}
		}
		else{
			if(k>=b*z){
				k-=b*z;
				ll u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
			}
			else if(D[x].second<=k){
				if(k<=z){
				k-=b*z;
				ll u=D[x-1].first, v=D[x-1].second + D[x].second;
				D.pob();D.pob();
				D.pub(mp(u,v));
				}
				else{
				k-=D[x].second;
				D[x].first--;
			}
			}
		}
		if(k<D[0].second && k<D[x].second) break;
	}

		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
		//cout<<D[D.size()-1].first<<' '<<D[0].first;

}


#include<bits/stdc++.h>
#include<algorithm>
#define pub push_back
#define puf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define ll long long
using namespace std;
main()
{
	ll n,k,a,b,x,i;
	map<ll,ll>M;
	deque<pair<ll,ll> >D;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>x;
		if(M.find(x)==M.end()){
			 M.insert(mp(x,1));
		}
		else M[x]++;
	}
	for(auto it=M.begin();it!=M.end();it++){
		D.pub(mp(it->first,it->second));//cout<<it->first<<' '<<it->second<<'\n';
	}
	while(D.size()>1){
		a=/*(D[1].first - D[0].first) */ D[0].second;
		x=D.size()-1;
		b=/*(D[x].first - D[x-1].first) */ D[x].second;
		if(a<b){
			int u=min(D[1].first-D[0].first,k/a);
			if(u==0) break;
			k-=u*a;
			D[1].second+=D[0].second;
			D[1].first=D[0].first+u;
			D.pof();
		}
		else{
			int u=min(D[x].first-D[x-1].first,k/b);
			if(u==0) break;
			k-=u*b;
			D[x-1].second+=D[x].second;
			D[x-1].first=D[x].first-u;
			D.pob();
		}
		if(k<D[0].second && k<D[x].second) break;
	}
		x=D[D.size()-1].first - D[0].first;
		cout<<x<<'\n';
		//cout<<D[D.size()-1].first<<' '<<D[0].first;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll c1=1;
    ll c2=1;
    ll i=0;
    ll j=n-1;
    ll flag=0;
    ll ans=0;
    while(k>0)
    {
        if(i==j)
        {
            cout<<0<<endl;
            return 0;
        }
        else
        {
            if(c1<c2)
            {
                if(k>=(a[i+1]-a[i])*c1)
                {
                    k-=(a[i+1]-a[i])*c1;
                    i++;
                    c1++;
                }
                else
                {
                        a[i]+=(k/c1);
                        k=0;

                }
            }
            else
            {
                if(k>=(a[j]-a[j-1])*c2)
                {
                    k-=(a[j]-a[j-1])*c2;
                    c2++;
                    j--;

                }
                else
                {
                        a[j]-=(k/c2);
                        k=0;
                }
            }
        }
    }
    ans+=a[j]-a[i];
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll c1=1;
    ll c2=1;
    ll i=0;
    ll j=n-1;
    ll flag=0;
    ll ans=0;
    while(k>0)
    {
        if(i==j)
        {
            cout<<0<<endl;
            return 0;
        }
        else
        {
            ll moves=min((a[i+1]-a[i])*c1,(a[j]-a[j-1])*c2);
            if(k<moves)
            {
                ans=(-1)*(k/min(c1,c2));
                flag=1;
                break;
            }
            else
            {
                ll dif1=min((a[i+1]-a[i]),moves/c1);
                ll dif2=min((a[j]-a[j-1]),moves/c2);
                if(dif1>dif2)
                {
                    if(dif1==a[i+1]-a[i])
                    {
                        c1++;
                        i++;
                    }
                    else
                    {
                        a[i]+=moves/c1;
                        moves=(c1*(moves/c1));
                    }
                }
                else if(dif2>dif1)
                {
                    if(dif2==a[j]-a[j-1])
                    {
                        c2++;
                        j--;
                    }
                    else
                    {
                        a[j]-=moves/c2;
                        moves=(c2*(moves/c2));
                    }
                }
                else
                {
                    if(dif1==a[i+1]-a[i])
                    {
                        c1++;
                        i++;
                    }
                    else if(dif2==a[j]-a[j-1])
                    {
                        c2++;
                        j--;
                    }
                }
                k-=moves;
            }
        }
    }
    ans+=a[j]-a[i];
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(LL i=j;i<=k;i++)
#define read        freopen("in.txt", "r", stdin)
#define write       freopen("out.txt", "w", stdout)
#define pf          prLLf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define PB push_back
#define F first
#define S second
#define MP make_pair

typedef long long LL;

const int MAX = (1e5) + 5;

LL preNeed[MAX], sufNeed[MAX], ara[MAX], k;

void solve()
{
    LL n;

    cin >> n >> k;
    FOR(i,0,n-1) cin >> ara[i];
    sort(ara, ara + n);

    LL c = 0;
    for(LL i = 0, j = 1; i < n; i++, j++)
    {
        c += ara[i];
        preNeed[i] = (LL)ara[i] * j;
        preNeed[i] -= c;
    }

    LL d = 0;
    for(LL i = n - 1, j = 1; i >= 0; i--, j++)
    {
        d += ara[i];
        sufNeed[i] = d;
        sufNeed[i] -= ((LL)ara[i] * j);
    }

//    FOR(i,0,n-1) cout << preNeed[i] << ' ';
//    cout << endl;
//    FOR(i,0,n-1) cout << sufNeed[i] << ' ';
//    cout << endl;

    LL prin = (1e9);

    FOR(i,0,n-1)
    {
        LL cank = k - preNeed[i];

        if(cank < 0) break;

        LL st = i + 1, en = n - 1, j = n - 1;

        while(st <= en)
        {
            LL mid = (st + en)>>1;

            if(sufNeed[mid] <= cank) en = mid - 1, j = min(mid, j);
            else st = mid + 1;
        }

        LL extra = cank - sufNeed[j];

        LL l = i + 1, r = (n - j), x, y;
        ///cout << "Here " << i << ' ' << j << ' ' << extra << endl;

        x = ara[i]; y = ara[j];
        if(l < r && i < n - 1 && i < j)
        {
            LL canJump = extra / l;
            canJump = min(canJump, (ara[i + 1] - ara[i]));

            x += canJump;
            extra -= (canJump * l);

            LL canJumpDown = extra / r;
            y -= canJumpDown;
            extra -= (canJumpDown * r);
        }
        else
        {
            LL canJumpDown = extra / r;
            y -= canJumpDown;
            extra -= (canJumpDown * r);

            LL canJump = extra / l;
            canJump = min(canJump, (ara[i + 1] - ara[i]));

            x += canJump;
            extra -= (canJump * l);
        }

        prin = min(prin, (y - x));
    }

    cout << max((LL)0, prin) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    //read;
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(LL i=j;i<=k;i++)
#define read        freopen("in.txt", "r", stdin)
#define write       freopen("out.txt", "w", stdout)
#define pf          prLLf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define PB push_back
#define F first
#define S second
#define MP make_pair

typedef long long LL;

const int MAX = (1e5) + 5;

LL preNeed[MAX], sufNeed[MAX], ara[MAX], k;

void solve()
{
    LL n;

    cin >> n >> k;
    FOR(i,0,n-1) cin >> ara[i];
    sort(ara, ara + n);

    LL c = 0;
    for(LL i = 0, j = 1; i < n; i++, j++)
    {
        c += ara[i];
        preNeed[i] = (LL)ara[i] * j;
        preNeed[i] -= c;
    }

    LL d = 0;
    for(LL i = n - 1, j = 1; i >= 0; i--, j++)
    {
        d += ara[i];
        sufNeed[i] = d;
        sufNeed[i] -= ((LL)ara[i] * j);
    }

//    FOR(i,0,n-1) cout << preNeed[i] << ' ';
//    cout << endl;
//    FOR(i,0,n-1) cout << sufNeed[i] << ' ';
//    cout << endl;

    LL prin = (1e9);

    FOR(i,0,n-1)
    {
        LL cank = k - preNeed[i];

        if(cank < 0) break;

        LL st = i + 1, en = n - 1, j = n - 1;

        while(st <= en)
        {
            LL mid = (st + en)>>1;

            if(sufNeed[mid] <= cank) en = mid - 1, j = min(mid, j);
            else st = mid + 1;
        }

        LL extra = cank - sufNeed[j];

        LL l = i, r = (n - j), x, y;
        ///cout << "Here " << i << ' ' << j << ' ' << extra << endl;

        x = ara[i]; y = ara[j];
        if(l < r && i < n - 1 && i < j)
        {
            LL canJump = extra / l;
            canJump = min(canJump, (ara[i + 1] - ara[i]));

            x += canJump;
            extra -= (canJump * l);

            LL canJumpDown = extra / r;
            y -= canJumpDown;
            extra -= (canJumpDown * r);
        }
        else
        {
            LL canJumpDown = extra / r;
            y -= canJumpDown;
            extra -= (canJumpDown * r);

            LL canJump = extra / l;
            canJump = min(canJump, (ara[i + 1] - ara[i]));

            x += canJump;
            extra -= (canJump * l);
        }

        prin = min(prin, (y - x));
    }

    cout << max((LL)0, prin) << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    //read;
    solve();
    return 0;
}