fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = (0 until n).map { readLine()!!.toLong() }.toLongArray()
    a.sort()

    (0 until 2)
            .map {
                a.reverse()
                val p = LongArray(n)
                var cur = 0

                for (i in 2 until n - 1 step 2) {
                    p[i] = a[cur++]
                }

                p[0] = a[cur++]
                p[n - 1] = a[cur++]

                for (i in 1 until n - 1 step 2) {
                    p[i] = a[cur++]
                }

                (1 until n).map { i -> Math.abs(p[i] - p[i - 1]) }.sum()
            }
            .max()
            .let { println(it) }
}
