
fun main(args:Array<String>): Unit {
    val n = readLine()!!.toInt()
    val nums = Array(n){readLine()!!.toLong()}.sortedArray()
    if (n % 2 == 1){
        val min = nums.take(n / 2)
        val mid = nums[n / 2]
        val max = nums.takeLast(n / 2)
        val minMax = min.last()
        val maxMin = max.first()
        println(
                if (mid - minMax < maxMin - mid) max.sum() * 2 - min.sum() * 2 - mid + minMax
                else max.sum() * 2 - min.sum() * 2 + mid - maxMin
        )
    }else {

        println(
                nums.takeLast(n / 2).sum() * 2 - nums.take(n / 2).sum() * 2 - nums.takeLast(n / 2).min()!! + nums.take(n / 2).max()!!
        )
    }
}