n
n = gets.chomp.to_i
array=Array.new
for i in 0..n-1 do
	array[i]=gets.chomp.to_i
end


array=array.sort
reverse=array.reverse
minarray=Array.new
maxarray=Array.new



for i in 0..n-1 do

	if(i==0)
		minarray[0]=array[0]
		array.shift()
	elsif(i%4==1)
		minarray.insert(0,array.pop)

	elsif(i%4==2)
		minarray.push(array.pop)

	elsif(i%4==3)
		minarray.insert(0,array.first)
		array.shift()

	else
		minarray.push(array.first)
		array.shift()

	end
end


for i in 0..n-1 do

	if(i==0)
		maxarray[0]=reverse[0]
		reverse.shift()
	elsif(i%4==1)
		maxarray.insert(0,reverse.pop)
	elsif(i%4==2)
		maxarray.push(reverse.pop)
	elsif(i%4==3)
		maxarray.insert(0,reverse.first)
		reverse.shift()
	else
		maxarray.push(reverse.first)
		reverse.shift()
	end
end


sum1=0
sum2=0

for i in 0..n-2 do
		sum1 += (minarray[i]-minarray[i+1]).abs
end

for i in 0..n-2 do
		sum2 += (maxarray[i]-maxarray[i+1]).abs
end

puts [sum1,sum2].max