n = gets.to_i
ary = []
n.times do
  ary << gets.to_i
end

ary = ary.sort
cnt = 0
cntL = 1
cntR = n - 1

ary2 = [ary[0]]
(n-1).times do
  case cnt % 4
  when 0
    ary2 << ary[cntR]
    cntR -= 1
  when 1
    ary2.unshift(ary[cntR])
    cntR -= 1
  when 2
    ary2 << ary[cntL]
    cntL += 1
  when 3
    ary2.unshift(ary[cntL])
    cntL += 1
  else
  end
  cnt += 1
end

ans = 0
(n-1).times do |i|
  ans += (ary2[i + 1] - ary2[i]).abs
end

puts ans
