n = gets.chomp.to_i

a = []
for i in 0..(n - 1) do
    a[i] = gets.chomp.to_i
end

sorted_a = a.sort

right = left = sorted_a[0]
s_a = sorted_a[1,sorted_a.size]

m = s_a.size/2
smaller = s_a[0, m]
bigger = s_a[m, s_a.size - m].reverse

b = 0
sum = 0
while true do
    if smaller.size == 0 and bigger.size == 0 then
        break
    end
    add = []
    if b == 0 then
        add = bigger.take(2)
        bigger = bigger.drop(2)
    else
        add = smaller.take(2)
        smaller = smaller.drop(2)
    end
    if add.size == 2
        sum += (add[0] - left).abs + (add[1] - right).abs
        left = add[0]
        right = add[1]
    elsif add.size == 1
        num = add[0]
        left_dif = (num - left).abs
        right_dif = (num - right).abs
        if left_dif > right_dif then
            sum += left_dif
            left = num
        else
            sum += right_dif
            right = num
        end
    end
    b += 1
    b %= 2
end

puts(sum)
