#!/usr/bin/ruby
# encoding: utf-8

n = gets.to_i
$a = Array.new
for i in 0..n-1
  $a[i] = gets.to_i
end
  
# 昇順
$a.sort!
sum = 0
sum1= 0
sum2= 0

$a_copy1 = Marshal.load(Marshal.dump($a))
$a_copy2 = Marshal.load(Marshal.dump($a))
$a_copy3 = Marshal.load(Marshal.dump($a))
$a_copy4 = Marshal.load(Marshal.dump($a))
$a_copy5 = Marshal.load(Marshal.dump($a))

if n.odd? then
  b1 = ($a[n/2] - $a[n-1]).abs
  b2 = ($a[n/2] - $a[0]).abs

  sum1 = b1
  $a.delete_at(n/2)
  ap = $a.pop
# puts "ap = #{ap}"
  while $a.size >= 1 do
    as = $a.shift
#   puts "as = #{as}"
    sum1 += (ap - as).abs
    if  $a.size >= 1 then
      ap = $a.pop
#     puts "ap = #{ap}"
      sum1 += (ap - as).abs
    end
  end    

  sum2 = b2
  $a_copy1.delete_at(n/2)
  as = $a_copy1.shift
# puts "as = #{as}"
  while $a_copy1.size >= 1 do
    ap = $a_copy1.pop
#   puts "ap = #{ap}"
    sum2+= (ap - as).abs
    if  $a_copy1.size >= 1 then
      as = $a_copy1.shift
#     puts "as = #{as}"
      sum2 += (ap - as).abs
    end
  end    

  if sum1 >= sum2 then
    puts sum1
  else
    puts sum2
  end
  exit

# nが偶数の時 ===========================
else
  sum1 = 0
  sum2 = 0
  sum3 = 0
  sum4 = 0

  # pattern1 最初が n/2-1
  c1 = ($a_copy2[n/2-1] - $a_copy2[n-1]).abs
  c2 = ($a_copy2[n/2-1] - $a_copy2[0]).abs

  sum1 = c1
  $a_copy2.delete_at(n/2-1)
  ap = $a_copy2.pop
# puts "ap = #{ap}"
  while $a_copy2.size >= 1 do
    as = $a_copy2.shift
#   puts "as = #{as}"
    sum1 += (ap - as).abs
    if $a_copy2.size >= 1 then
      ap = $a_copy2.pop
#     puts "ap = #{ap}"
      sum1 += (ap - as).abs
    end
  end

  sum2 = c2
  $a_copy3.delete_at(n/2-1)
  as = $a_copy3.shift
# puts "as = #{as}"
  while $a_copy3.size >= 1 do
    ap = $a_copy3.pop
#   puts "ap = #{ap}"
    sum2 += (ap - as).abs
    if $a_copy3.size >= 1 then
      as = $a_copy3.shift
#     puts "as = #{as}"
      sum2 += (ap - as).abs
    end
  end
  

  # pattern2 最初が n/2
  d1 = ($a_copy4[n/2] - $a_copy4[n-1]).abs
  d2 = ($a_copy4[n/2] - $a_copy4[0]).abs

  sum3 = d1
  $a_copy4.delete_at(n/2)
  ap = $a_copy4.pop
# puts "ap = #{ap}"
  while $a_copy4.size >= 1 do
    as = $a_copy4.shift
#   puts "as = #{as}"
    sum3 += (ap - as).abs
    if $a_copy4.size >= 1 then
      ap = $a_copy4.pop
#     puts "ap = #{ap}"
      sum3 += (ap - as).abs
    end
  end

  sum2 = d2
  $a_copy5.delete_at(n/2)
  as = $a_copy5.shift
# puts "as = #{as}"
  while $a_copy5.size >= 1 do
    ap = $a_copy5.pop
#   puts "ap = #{ap}"
    sum2 += (ap - as).abs
    if $a_copy5.size >= 1 then
      as = $a_copy5.shift
#     puts "as = #{as}"
      sum2 += (ap - as).abs
    end
  end
end

ans = Array.new(4)
ans[0] = sum1
ans[1] = sum2
ans[2] = sum3
ans[3] = sum4

puts ans.max
