"use strict";
function Main(input) {
    let lines = input.split("\n").map(function (value) { return value - 0; });
    let N = lines.shift();
    let nums = new Array(N);
    for (let n = 0; n < N; n++) nums[n] = lines.shift();
    nums.sort(function (a, b) { return b - a; });
    let ary = new Array(N);
    let m = 0;
    let r = N - 1;
    for (let l = 0; l < N / 2; l++ , r--) {
        ary[m++] = nums[l];
        if (m < N) ary[m++] = nums[r];
    }
    let s0 = 0, s1 = 0, s2 = 0;
    for (let n = 0; n < N - 1; n++) {
        r = (Math.abs(ary[n] - ary[n + 1]));
        s0 += r;
    }
    m = N - 1;
    for (let n = 0; n < N - 1; n++) {
        r = (Math.abs(ary[m] - ary[n]));
        s1 += r;
        m = n;
    }
    m = N - 1;
    for (let n = 0; n < N - 1; n++) {
        r = (Math.abs(ary[m] - ary[n]));
        s2 += r;
        m = n + 2;
    }
    console.log(Math.max(...[s0, s1, s2]));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
