#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define N 200005
#define cout2(x, y) cout << x << " " << y << endl
using namespace std;
int x[N], dis_left[N], dis_right[N];
int ac1[N], ac2[N];
int main(){
int n;
while(cin>>n){
for(int i = 1; i <= n; i++)scanf("%d", &x[i]);
sort(x + 1, x + n + 1);
int total = x[n] - x[1];
for(int i = 1; i <= n - 1; i++){
dis_left[i] = x[i + 1] - x[i];
ac1[i] = ac1[i - 1] + dis_left[i];
}
for(int i = n; i >= 2; i--){
dis_right[i] = x[i] - x[i - 1];
ac2[i] = ac2[i + 1] + dis_right[i];
}
int maxi = 0;
for(int i = 0, j; i <= (n - 1)/2; i++){
j = (n - 1)/2 - i;
maxi = max(maxi, ac1[i] + ac2[n - j + 1]);
}
cout << total - maxi << endl;
}
}
CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIHBiKHgpIHB1c2hfYmFjayh4KQojZGVmaW5lIE4gMjAwMDA1CiNkZWZpbmUgY291dDIoeCwgeSkgY291dCA8PCB4IDw8ICIgIiA8PCB5IDw8IGVuZGwKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgeFtOXSwgZGlzX2xlZnRbTl0sIGRpc19yaWdodFtOXTsKaW50IGFjMVtOXSwgYWMyW05dOwoKaW50IG1haW4oKXsKCglpbnQgbjsKCXdoaWxlKGNpbj4+bil7CgkJCgkJZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspc2NhbmYoIiVkIiwgJnhbaV0pOwoJCXNvcnQoeCArIDEsIHggKyBuICsgMSk7CgkJCgkJaW50IHRvdGFsID0geFtuXSAtIHhbMV07CgoJCWZvcihpbnQgaSA9IDE7IGkgPD0gbiAtIDE7IGkrKyl7CgkJCQoJCQlkaXNfbGVmdFtpXSA9IHhbaSArIDFdIC0geFtpXTsKCQkJYWMxW2ldID0gYWMxW2kgLSA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