#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>

#define MAXN 100050
#define INF 2100000000

using namespace std;

int n, a[MAXN], b[MAXN], c[MAXN];

int cut(int l, int r, int d[])
{
    int m = 0;
    d[m++] = a[r--];
    while (l <= r) {
        d[m++] = a[l++];
    }
    return m;
}

long long solve0()
{
    sort(a, a + n);
    long long ans = 0;
    int lnum = a[n - 1];
    int rnum = a[n - 1];
    int lpos = 0;
    int rpos = n - 2;
    while (lpos <= rpos) {
        if (lpos <= rpos) {
            ans += abs(rnum - a[lpos]);
            rnum = a[lpos];
            lpos++;
        }
        if (lpos <= rpos) {
            ans += abs(rnum - a[rpos]);
            rnum = a[rpos];
            rpos--;
        }
        if (lpos <= rpos) {
            ans += abs(lnum - a[lpos]);
            lnum = a[lpos];
            lpos++;
        }

        if (lpos <= rpos) {
            ans += abs(lnum - a[rpos]);
            lnum = a[rpos];
            rpos--;
        }

    }
    return ans;
}

long long solve1()
{
    sort(a, a + n);
    long long ans = 0;
    int lnum = a[0];
    int rnum = a[0];
    int lpos = 1;
    int rpos = n - 1;
    while (lpos <= rpos) {
        if (lpos <= rpos) {
            ans += abs(rnum - a[rpos]);
            rnum = a[rpos];
            rpos--;
        }
        if (lpos <= rpos) {
            ans += abs(rnum - a[lpos]);
            rnum = a[lpos];
            lpos++;
        }
        if (lpos <= rpos) {
            ans += abs(lnum - a[rpos]);
            lnum = a[rpos];
            rpos--;
        }
        if (lpos <= rpos) {
            ans += abs(lnum - a[lpos]);
            lnum = a[lpos];
            lpos++;
        }
    }
    return ans;
}

long long solve2()
{
    sort(a, a + n);
    long long ans = a[n - 1] - a[0];
    pair<int, int> lnum, rnum;
    lnum = make_pair(a[0], 1);
    rnum = make_pair(a[n - 1], 0);
    int lpos = 1;
    int rpos = n - 2;
    while (lpos <= rpos) {
        if (lpos <= rpos) {
            int num = a[lpos];
            lpos++;

            int ltmp = -1;
            int rtmp = -1;

            if (lnum.second == 0)
                ltmp = abs(lnum.first - num);
            if (rnum.second == 0)
                rtmp = abs(rnum.first - num);

            if (ltmp > rtmp) {
                ans += ltmp;
                lnum = make_pair(num, 1);
                //printf("%d to left\n", num);
            } else {
                ans += rtmp;
                rnum = make_pair(num, 1);
                //printf("%d to right\n", num);
            }
        }
        if (lpos <= rpos) {
            int num = a[rpos];
            rpos--;

            int ltmp = -1;
            int rtmp = -1;

            if (lnum.second == 1)
                ltmp = abs(lnum.first - num);
            if (rnum.second == 1)
                rtmp = abs(rnum.first - num);

            if (ltmp > rtmp) {
                ans += ltmp;
                lnum = make_pair(num, 0);
                //printf("%d to left\n", num);
            } else {
                ans += rtmp;
                rnum = make_pair(num, 0);
                //printf("%d to right\n", num);
            }
        }
    }
    return ans;
}

long long solve4()
{
    long long ans = 0;
    sort(a, a + n);

    int cp = (n) / 2;
    reverse(a + cp, a + n);
    int nb = cut(0, cp - 1, b);
    int nc = cut(cp, n - 1, c);
    int now = c[0];
    int posb = 0;
    int posc = 1;
    while (posb < nb) {
        ans += abs(b[posb] - now);
        now = b[posb];
        posb++;
        ans += abs(c[posc] - now);
        now = c[posc];
        posc++;
    }
    return ans;
}

long long solve5()
{
    long long ans = 0;
    sort(a, a + n);
    int cp = (n + 1) / 2;
    reverse(a + cp, a + n);
    int nb = cut(0, cp - 1, b);
    int nc = cut(cp, n - 1, c);
    int now = b[0];
    int posb = 1;
    int posc = 0;
    while (posc < nc) {

        ans += abs(c[posc] - now);
        now = c[posc];
        posc++;
        ans += abs(b[posb] - now);
        now = b[posb];
        posb++;

    }
    return ans;
}

long long solve3()
{
    long long ans = max(solve4(), solve5());
    //sort(a, a + n);
    return ans;
}


int main()
{
    //freopen("c.txt", "r", stdin);
    while (cin >> n) {
        for (int i = 0; i < n; i++) {
            scanf("%d", a + i);
        }
        cout << max(solve0(), solve1()) << endl;
        //cout << solve3() << endl;
    }
    return 0;

}


Measured memory_bytes: 640