
function main(arg) {
    arg = arg.split("\n")
    var N = Number(arg.shift())
    var array = arg;
    var rar = arg.slice();
    var result = 0;
    var temp = 0;

    array = array.map(e => Number(e))
    array.sort(function(a, b) {
      return a - b;
    });
    
    if (N % 2 == 0) {
        for (j = 0; j < N / 2; j++) {
            rar[j * 2 + 1] = array[j];
            rar[j * 2] = array[j + N / 2];
        }

        for (k = 0; k < N - 1; k++) {
            result += Math.abs(rar[k] - rar[k + 1]);
        }
    } else {
        var center = N / 2;
        rar[center] = array[0];
        for (m = 1; m <= N / 2; m++) {
            if (m % 2 == 1) {
                rar[center - m] = array[N - m];
                rar[center + m] = array[N - m - 1];
            } else {
                rar[center - m] = array[m - 1];
                rar[center + m] = array[m];
            }

        }
        for (k = 0; k < N - 1; k++) {
            result += Math.abs(rar[k] - rar[k + 1]);
        }
        rar[center] = array[N - 1];
        for (m = 1; m <= N / 2; m++) {
            if (m % 2 == 0) {
                rar[center - m] = array[N - m];
                rar[center + m] = array[N - m - 1];
            } else {
                rar[center - m] = array[m - 1];
                rar[center + m] = array[m];
            }

        }
        for (k = 0; k < N - 1; k++) {
            temp += Math.abs(rar[k] - rar[k + 1]);
        }
        result = (result < temp) ? temp : result;
    }

    console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
