#!/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

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

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

# p "a = #{$a}"
  puts sum
  exit

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

  $a_copy = Marshal.load(Marshal.dump($a))

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

  if c1 >= c2 then
    sum1 = c1
    $a.delete_at(n/2-1)
    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
  else
    sum1 = c2
    $a.delete_at(n/2-1)
    as = $a.shift
#   puts "as = #{as}"
    while $a.size >= 1 do
      ap = $a.pop
#     puts "ap = #{ap}"
      sum1 += (ap - as).abs
      if $a.size >= 1 then
        as = $a.shift
#       puts "as = #{as}"
        sum1 += (ap - as).abs
      end
    end
  
  end

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

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

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

