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

a = [as.shift]
loop do
    x = as.pop
    break unless x
    a.unshift x

    x = as.pop
    break unless x
    a.push x

    x = as.shift
    break unless x
    a.unshift x

    x = as.shift
    break unless x
    a.push x
end

ret = 0
a.each_cons(2) do |m,n|
    ret += (m-n).abs
end
ret_a = ret

a = [as.pop]
loop do
    x = as.pop
    break unless x
    a.unshift x

    x = as.pop
    break unless x
    a.push x

    x = as.shift
    break unless x
    a.unshift x

    x = as.shift
    break unless x
    a.push x
end

ret = 0
a.each_cons(2) do |m,n|
    ret += (m-n).abs
end

puts [ret_a,ret].max