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!

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

p result

p calc(result)
