#include <bits/stdc++.h>
using namespace std;
int a[1005];
int b[1005];
int main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
if(n%2){
for(int i=1;i<=n/2;i++){
a[i]+=k;
b[i]=a[i];
}
for(int i=n/2+2;i<=n;i++){
a[i]-=k;
b[i]=a[i];
}
b[n/2+1]=a[n/2+1]+k;
sort(b+1,b+n+1);
a[n/2+1]-=k;
sort(a+1,a+n+1);
cout<<min(b[n]-b[1],a[n]-a[1]);
}else{
for(int i=1;i<=n/2;i++){
a[i]+=k;
}
for(int i=n/2+1;i<=n;i++){
a[i]-=k;
}
sort(a+1,a+n+1);
cout<<a[n]-a[1];
}
return 0;
}
WA50pts