n=gets.chomp.to_i
a=[]

n.times do |i|
  a[i] = gets.chomp.to_i
end

def abs(n)
  return -n if n<0
  return n
end

a = a.sort
left = []
right = []

left[0] = a[0]
right[0] = a[0]
tmp = 2
(n-1).downto(1) do |i|
  if tmp%2 == 0
    left[tmp/2] = a[i]
  else
    right[tmp/2] = a[i]
  end
  tmp += 1
end


tmp = left[0]
sum = 0
for i in left do
  sum += abs(tmp-i)
  tmp = i
end

tmp = left[0]

for i in right do
  sum += abs(tmp-i)
  tmp = i
end

puts sum