#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  ll n;cin>>n;
  vector<ll>num(n);
  for(int i=0;i<n;i++)
    cin>>num[i];
  sort(ALL(num));
  vector<ll>num1;
  vector<ll>num2;
  ll ans=0;
  for(int i=0;i<n/2;i++)
    num1.pb(num[i]);
  for(int i=n/2;i<n;i++)
    num2.pb(num[i]);
  ll hai[n+10]={};
  if(n%2){
    if(n%4 == 1){
      int plus=false;
      reverse(ALL(num2));
      int now=n/2;
      int cnt=2;
      for(int i=0;i<num2.size();i++){
	hai[now]=num2[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      cnt=2;
      now=n/2-1;
      plus=true;
      for(int i=0;i<num1.size();i++){
	hai[now]=num1[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      ll sum=0;
      for(int i=1;i<n;i++){
	sum+=abs(hai[i]-hai[i-1]);
      }
      ans=max(sum,ans);


     

      num1.clear();
      num2.clear();
      for(int i=0;i<n/2+1;i++)
	num1.pb(num[i]);
      for(int i=n/2+1;i<n;i++)
	num2.pb(num[i]);
      reverse(ALL(num2));
      plus=false;
      now=n/2;
      cnt=2;
      sum=0;
      for(int i=0;i<num1.size();i++){
	hai[now]=num1[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      cnt=2;
      now=n/2-1;
      plus=true;
      for(int i=0;i<num2.size();i++){
	hai[now]=num2[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      for(int i=1;i<n;i++)
	sum+=abs(hai[i]-hai[i-1]);
    
      ans=max(sum,ans);
    }else{
      int plus=false;
      reverse(ALL(num2));
      int now=n/2;
      int cnt=2;
      for(int i=0;i<num1.size();i++){
	hai[now]=num1[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      cnt=2;
      now=n/2-1;
      plus=true;
      for(int i=0;i<num2.size();i++){
	hai[now]=num2[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      ll sum=0;
      for(int i=1;i<n;i++){
	sum+=abs(hai[i]-hai[i-1]);
      }
      ans=max(sum,ans);
      num1.clear();
      num2.clear();
      for(int i=0;i<n/2+1;i++)
	num1.pb(num[i]);
      for(int i=n/2+1;i<n;i++)
	num2.pb(num[i]);
      reverse(ALL(num2));
      plus=false;
      now=n/2;
      cnt=2;
      sum=0;
      for(int i=0;i<num2.size();i++){
	hai[now]=num2[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      cnt=2;
      now=n/2-1;
      plus=true;
      for(int i=0;i<num1.size();i++){
	hai[now]=num1[i];
	if(plus){
	  plus=false;
	  now+=cnt;
	  cnt+=2;
	}else{
	  plus=true;
	  now-=cnt;
	  cnt+=2;
	}
      }
      for(int i=1;i<n;i++)
	sum+=abs(hai[i]-hai[i-1]);
 
      ans=max(sum,ans);
    }
  }else{
    int plus=false;
    reverse(ALL(num2));
    int now=n/2;
    int cnt=2;
    for(int i=0;i<num2.size();i++){
      hai[now]=num2[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    cnt=2;
    now=n/2-1;
    plus=true;
    for(int i=0;i<num1.size();i++){
      hai[now]=num1[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    ll sum=0;
    for(int i=1;i<n;i++){
      //cout<<hai[i]<<" ";
      sum+=abs(hai[i]-hai[i-1]);
    }
    //cout<<endl;
    ans=max(sum,ans);

     plus=false;
     now=n/2;
     cnt=2;
    for(int i=0;i<num1.size();i++){
      hai[now]=num1[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    cnt=2;
    now=n/2-1;
    plus=true;
    for(int i=0;i<num2.size();i++){
      hai[now]=num2[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    sum=0;
    for(int i=1;i<n;i++){
      sum+=abs(hai[i]-hai[i-1]);
    }
    ans=max(sum,ans);


    plus=true;
    now=n/2;
    cnt=2;
    for(int i=0;i<num2.size();i++){
      hai[now]=num2[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    cnt=2;
    now=n/2-1;
    plus=false;
    for(int i=0;i<num1.size();i++){
      hai[now]=num1[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
     sum=0;
    for(int i=1;i<n;i++){
      //cout<<hai[i]<<" ";
      sum+=abs(hai[i]-hai[i-1]);
    }
    //cout<<endl;
    ans=max(sum,ans);

     plus=true;
     now=n/2;
     cnt=2;
    for(int i=0;i<num1.size();i++){
      hai[now]=num1[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    cnt=2;
    now=n/2-1;
    plus=false;
    for(int i=0;i<num2.size();i++){
      hai[now]=num2[i];
      if(plus){
	plus=false;
	now+=cnt;
	cnt+=2;
      }else{
	plus=true;
	now-=cnt;
	cnt+=2;
      }
    }
    sum=0;
    for(int i=1;i<n;i++){
      sum+=abs(hai[i]-hai[i-1]);
    }
    ans=max(sum,ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2808