/*   LazyBones
*
*/

#include <bits/stdc++.h>
#include<cctype>
#include <sstream>
#include<ctime>
using namespace std;
#define rep(i,b) for(int i=0;i<b;i++)
#define getarr(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define disparr(a,n) for(int i=0;i<n;i++){cout<<a[i];}cout<<"\n";
#define disparrs(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";
#define disparrl(a,n) for(int i=0;i<n;i++){cout<<a[i]<<"\n";}cout<<"\n";
#define mem0(a) memset(a,0,sizeof(a));
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define F first
#define S second
//#define nu 100001
#define M 1000000007
#define mul(x,y) ((ll)(x)*(y))%M
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 0x3f3f3f3f
#define MOD 998244353

int MODU(int a, int b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll max3(ll a,ll b,ll c)
{
    return max(c,max(a,b));
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll max(ll a,ll b)
{
    return (a>b)?a:b;
}
ll min(ll a,ll b)
{
    return (a<b)?a:b;
}
ld min(ld a,ld b)
{
    return (a<b)?a:b;
}
ll gcd(ll a,ll b)
{
    if(b==1)
    return 1;
    else if(a%b==0)
    return b;
    else
    return gcd(b,a%b);
}
ll mod(ll x){
    if(x>=0)
    return x;
    else
    return -x;
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}

void cycle(vll c,vi& v,int u, ll& val,vi& len,int ini){
    //cout<<u<<endl;
    v[u]=1;
    if(c[u]==u){
        v[u]=2;
        val=1;
        return;
    }
    if(v[c[u]]==2){
        return;
    }
    if (v[c[u]]==1){
        if(v[c[u]]!=ini)
            return;
        val=len[u]+1-len[c[u]];
        //cout<<val<<" hf"<<endl;
        v[u]=2;
        return;
    }
    len[c[u]]=len[u]+1;
    //cout<<u<<endl;
    cycle(c,v,c[u],val,len,ini);
    v[u]=2;
    return;

}



int main()
{
    fastio;
    ll n;
    cin>>n;
    int arr[n];
    getarr(arr,n)
    sort(arr,arr+n);
    if(n&1){
        int neg = n/2;
        ll res1 =0,res2=0;
        int i;
        for(i=0;i<neg;i++){
            res1+= -2*arr[i];
        }
        res1 +=(arr[i]+arr[i+1]);
        i+=2;
        for(;i<n;i++){
            res1+=2*arr[i];
        }
        neg = n-n/2-2;
        for(i=0;i<neg;i++){
            res2+= -2*arr[i];
        }
        res2 +=-1*(arr[i]+arr[i+1]);
        i+=2;
        for(;i<n;i++){
            res2+=2*arr[i];
        }
        cout<<max(res1,res2);
    }
    else
    {
        ll res=0;
        int neg = (n-2)/2;
        int i;
        for(i=0;i<neg;i++)
            res+=-2*arr[i];
        res-=arr[i];
        res+=arr[i+1];
        i+=2;
        for(;i<n;i++)
            res+=2*arr[i];
        cout<<res;
    } 
    return 0;
}


Measured memory_bytes: 640