#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define sc(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int> 
#define pli pair<ll,int>
#define pil pair<int,ll>  
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb(x) push_back(x)
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define clr(x) memset(x,0,sizeof(x))
#define sws ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pi acos(-1)
#define rep(I, N) for (ll I = 0; I < (N); ++I)
#define repp(I, a, B) for (ll I = (a); I <= (B); ++I)
using namespace std;
#define TRACE

#ifdef TRACE
#define t(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define t(...)
#endif
string itos(ll i) 
{
    string s = "";
    while(i)
    {
        s += char(i % 10 + '0');
        i /= 10; 
    }
    reverse(all(s));  
    return s; 
}
ll stoi(string &s) 
{
    ll tot = 0; 
    for (int i = (int)s.length() - 1, j = 1; i >= 0; i--, j *= 10) 
    {
        tot += j * (s[i] + '0'); 
    }  
    return tot; 
}
ll pwr(ll base, ll p, ll mod)
{
    ll ans = 1;
    while(p)
    {
        if(p & 1) ans = (ans * base) % mod;
        base = (base * base) % mod;
        p /= 2;
    }
    return ans;
}
ll gcd(ll a, ll b)
{
    if(b == 0)  return a;
     return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
    return (a*b*1LL) / gcd(a, b);
}/*
ll fact[MAX];
ll invfact[MAX];
ll C(ll n, ll k) 
{
    return ((fact[n] * invfact[n - k]) % MOD * invfact[k]) % MOD;
}
void Combpre()
{
    fact[0] = 1;
    invfact[0] = 1;
    for(ll i = 1; i < N; ++i) 
    {
        fact[i] = (i * fact[i - 1]) % MOD;
        invfact[i] = (invfact[i - 1] * pwr(i, MOD - 2, MOD)) % MOD;
    }
}
bool isPrime[MAX];
void sieve(int n) 
{
    for(int i = 0; i <= n;++i) 
    {
        isPrime[i] = true;
    }
    isPrime[0] = false;
    isPrime[1] = false;
    for(int i = 2; i * i <= n; ++i) 
    {
         if(isPrime[i] == true) 
         {
             for(int j = i * i; j <= n ;j += i)
                 isPrime[j] = false;
        }
    }
}*/

const int N = 2e5 + 10;
const int M = 2e5 + 5;
const int LN = 30;
const int BLOCK = 1000;
const int MAX = 1e6 + 5;
const int MOD = 1e9 + 7;


int a[N], t[N];


int main()
{
    sws;
    srand(time(NULL));
    cout << fixed << setprecision(10);
    clock_t clk;
    clk = clock();
    

    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);


    int n;
    ll ans = 0;
    cin >> n;
    repp(i,1,n) cin >> a[i]; //repp(i,1,n) cout << a[i] <<" "; cout <<" \n";
    sort(a + 1, a + n + 1);
    t[100005] = a[1];
    int ptr = 100005;
    int l = 2, r = n;
    int tot = 1, cnt = 0;
    while(true)
    {
        cnt++;
        tot += 2; //t(cnt, tot, l, r);
        if(cnt & 1)
        {
            if(tot > n)
            {
                t[ptr - cnt] = a[r];
            }
            else
            {
                t[ptr + cnt] = a[r - 1];
                t[ptr - cnt] = a[r];
                r -= 2;
            }
        }
        else
        {
            if(tot > n)
            {
                t[ptr - cnt] = a[l];
            }
            else
            {
                t[ptr + cnt] = a[l + 1];
                t[ptr - cnt] = a[l];
                l += 2;
            }
        }
        if(tot >= n)
            break;
    }
    //repp(i,ptr-cnt,ptr+cnt) cout << t[i] << " "; cout <<"\n";
    if(n&1) repp(i,ptr-cnt,ptr+cnt-1) ans += abs(t[i] - t[i + 1]);
    else repp(i,ptr-cnt,ptr+cnt-2) ans += abs(t[i] - t[i + 1]);
    clr(t);
    t[ptr] = a[n];
    cnt = 0; tot = 1;
    l = 1, r = n - 1;
    while(true)
    {
        cnt++;
        tot += 2; //t(cnt, tot, l, r);
        if(cnt & 1)
        {
            if(tot > n)
            {
                t[ptr - cnt] = a[l];
            }
            else
            {
                t[ptr + cnt] = a[l + 1];
                t[ptr - cnt] = a[l];
                l += 2;
            }
        }
        else
        {
            if(tot > n)
            {
                t[ptr - cnt] = a[r];
            }
            else
            {
                t[ptr + cnt] = a[r - 1];
                t[ptr - cnt] = a[r];
                r -= 2;
            }
        }
        if(tot >= n)
            break;
    }
    ll _ans = 0;
    //repp(i,ptr-cnt,ptr+cnt) cout << t[i] << " "; cout <<"\n";
    if(n&1) repp(i,ptr-cnt,ptr+cnt-1) _ans += abs(t[i] - t[i + 1]);
    else repp(i,ptr-cnt,ptr+cnt-2) _ans += abs(t[i] - t[i + 1]); //t(_ans, ans);
    cout << max(ans,_ans);


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    
    return 0;
}

Measured memory_bytes: 1408