import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val aList = mutableListOf<Long>()
    
    for (i in 1..N) {
        aList.add(readInputLine().toLong())
    }
    
    val sortedArr = aList.sorted().toLongArray()
    
    var work = LongArray(N)
    
    var l = 0
    var r = N - 1
    
    for (i in 1..N - 2) {
        work[i] = sortedArr[if (i % 2 == 1) l++ else r--]
    }
    work[0] = sortedArr[l]
    work[N - 1] = sortedArr[r]

    var ans1 = 0L
    
    for (i in 1..N - 1) {
        ans1 += Math.abs(work[i] - work[i - 1])
    }
    
    work = LongArray(N)

    l = 0
    r = N - 1
    
    for (i in 1..N - 2) {
        work[i] = sortedArr[if (i % 2 == 1) r-- else l++]
    }
    work[0] = sortedArr[l]
    work[N - 1] = sortedArr[r]

    var ans2 = 0L
    
    for (i in 1..N - 1) {
        ans2 += Math.abs(work[i] - work[i - 1])
    }
    
    println(Math.max(ans1, ans2))
}

fun readInputLine(): String {
    return readLine()!!
}
