N,*as=$<.read.split.map(&:to_i)
as = as.sort!

l = 0
r = N-1
ret = as[r]-as[l]
(N/2-1).times do
    ret += (as[l+1] - as[r]).abs
    ret += (as[l] - as[r-1]).abs
    l += 1
    r -= 1
end

if N.odd?
    center = N/2
    ret += [
        (as[center]-as[center-1]).abs,
        (as[center]-as[center+1]).abs,
    ].max
end

puts ret