n = gets.to_i
arr = (0...n).map{|i|
  gets.to_i
}
arr.sort!

res_arr=[]
if arr.size()==3 then
  res_arr=[arr[1], arr[0], arr[2]]
else
  idx_arr=[]
  (0...n).each{|i|
    if i%2==0 then
      idx_arr.push(i/2)
    else
      idx_arr.push(-(i+1)/2)
    end
  }
  
  tmp_arr=[]
  (idx_arr).each{|i|
    tmp_arr.push(arr[i])
  }
  
  (0...n).each{|i|
    res_arr.push(tmp_arr[i])
    if i%2==0 then res_arr.reverse! end
  }
end

sa = 0
(0...n-1).each{|i|
  sa += (res_arr[i] - res_arr[i+1]).abs
}
puts sa