N = gets.to_i
A = N.times.map{gets.to_i}.sort
B = []
B << A.shift
while !A.empty?
    B.unshift A.pop
    B.push A.pop if !A.empty?
    B.unshift A.shift if !A.empty?
    B.push A.shift if !A.empty?
end
ans = 0
(N - 1).times{|i|
    ans += (B[i] - B[i + 1]).abs
}
puts ans