N = gets.to_i
A = N.times.map{gets.to_i}.sort
B = []
B << A.shift
while !A.empty?
    if 1 < A.length then
        x = A.pop
        y = A.pop
        if (B.first - x).abs + (B.last - y).abs < (B.first - y).abs + (B.last - x).abs then
            B.push x
            B.unshift y
        else
            B.push y
            B.unshift x
        end
    else
        x = A.pop
        if (B.first - x).abs < (B.last - x).abs then
            B.push x
        else
            B.unshift x
        end
    end
    next if A.empty?
    if 1 < A.length then
        x = A.shift
        y = A.shift
        if (B.first - x).abs + (B.last - y).abs < (B.first - y).abs + (B.last - x).abs then
            B.push x
            B.unshift y
        else
            B.push y
            B.unshift x
        end
    else
        x = A.pop
        if (B.first - x).abs < (B.last - x).abs then
            B.push x
        else
            B.unshift x
        end
    end
end
ans = 0
(N - 1).times{|i|
    ans += (B[i] - B[i + 1]).abs
}
puts ans