fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = LongArray(N) { readLine()!!.toLong() }

    A.sort()

    if (N % 2 == 0) {
        val m = N / 2
        println(A.slice(m until A.size).sum() * 2 - A.slice(0 until m).sum() * 2 - A[m] + A[m - 1])
    } else {
        val m = N / 2
        val res = Math.max(
            A.slice(m until A.size).sum() * 2 - A.slice(0 until m).sum() * 2 - A[m] - A[m + 1],
            A.slice(m + 1 until A.size).sum() * 2 - A.slice(0 until m + 1).sum() * 2 + A[m] + A[m - 1]
        )

        println(res)
    }
}
