N = gets.to_i

def calc(list)
	prev = list[0]
	sum = 0
	list[1..-1].each{|n|
		sum += (prev - n).abs
		prev = n
	}
	sum
end

list = []
N.times{
	list << gets.to_i
}

list.sort!

def arrange(list)
	first = 0
	last = N - 1
	result = [list[first]]
	first += 1
	while first <= last
		result << list[last]
		last -= 1
		break if first > last
		result.unshift(list[last])
		last -= 1
		break if first > last
		result << list[first]
		first += 1
		break if first > last
		result.unshift(list[first])
		first += 1
	end
	result
end

c1 = calc(arrange(list))
c2 = calc(arrange(list.reverse))

puts [c1, c2].max
