import Foundation


func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let n = Int(readLine()!)!

    let A = (1...n).map { _ in Int(readLine()!)! }.sorted()

    // 1 1 3 4 5 9
    // 3 [9 1] [5 1] [4]
    // [最大 最小]のコンビを続け、最後の一つは前と後ろ差が大きいほうを

    // 1 2 3 6 8
    // 3 [8 1] [6 2] --> 5 7 5 4 == 21

    let mid = n / 2

    let small = A[..<mid]
    let large = Array(A[mid...].reversed())

    var newA = [Int]()
    for i in 0..<mid {
        newA.append(large[i])
        newA.append(small[i])
    }

    let last = n % 2 == 0 ? newA.popLast()! : large.last!

    var ans = 0
    for i in 0..<newA.count-1 {
        ans += abs(newA[i] - newA[i+1])
    }
    print(ans + max(abs(last - newA.first!), abs(last - newA.last!)))
}


main()