fun main(args: Array<String>) {
    tenka12018beginner_c()
}

fun tenka12018beginner_c() {
    val n = readLine()!!.toInt()
    val aList = (1..n).map { readLine()!!.toLong() }
        .sorted().toLongArray()

    var beforeSmaller = aList.first()
    var beforeBigger = aList.last()
    var answer = beforeBigger - beforeSmaller
    for (i in 1 until aList.size / 2) {
        val currSmaller = aList[i]
        val currBigger = aList[aList.lastIndex - i]
        answer += (beforeBigger - currSmaller) + (currBigger - beforeSmaller)
        beforeSmaller = currSmaller
        beforeBigger = currBigger
    }

    if (n % 2 != 0) answer += Math.max(
        aList[aList.lastIndex / 2 + 1] - aList[aList.lastIndex / 2],
        aList[aList.lastIndex / 2] - aList[aList.lastIndex / 2 - 1]
    )

    println(answer)
}
