fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = (1..N).map { readLine()!!.toLong() }.sortedDescending()
    var result = 0L; var result2 = 0L
    if (N % 2 == 0) {
        for (i in 0 until (N / 2 - 1)) result += A[i] * 2
        result += A[N / 2 - 1]
        result -= A[N / 2]
        for (j in (N / 2 + 1) until N) result -= A[j] * 2
    } else {
        for (i in 0 until (N / 2 - 1)) result += A[i] * 2
        result += A[N / 2 - 1] + A[N / 2]
        for (j in (N / 2 + 1) until N) result -= A[j] * 2

        for (i in 0 until (N / 2)) result2 += A[i] * 2
        result2 -= A[N / 2] + A[N / 2 + 1]
        for (j in (N / 2 + 2) until N) result2 -= A[j] * 2
    }
    println(Math.max(result, result2))
}