"use strict";
function Main(input) {
    let lines = input.split("\n").map((v) => v - 0);
    let N = lines.shift();
    let nums = new Array(N);
    for (let n = 0; n < N; n++) nums[n] = lines.shift();
    nums.sort((a, b) => a - b);
    const even = N % 2 == 0;
    const H = Math.ceil(N / 2);
    let ans = 0;
    if (even) {
        for (let n = 0, m = N - 1; n < H; n++, m--) {
            if (n < H - 1) {
                ans -= nums[n] * 2;
                ans += nums[m] * 2;
            } else {
                ans -= nums[n];
                ans += nums[m];
            }
        }
    } else {
        for (let n = H; n < N; n++) ans += nums[n] * 2;
        ans -= (nums[H - 1] + nums[H - 2]);
        for (let n = 0; n < H - 2; n++) ans -= nums[n] * 2;
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
