object Main extends App{
val in=io.Source.stdin.getLines.map(_.toInt).toSeq
val nums=in.tail.sorted

def func(acc:Seq[Int], num:Seq[Int]):Seq[Int]={
if(num.size==0) return acc
if(num.size>=2) func( (num.head +: acc :+ num.last),  num.tail.init)
else if (num.size==1){
 //Math.max(
  func( (num.head +: acc),  num.tail)
  //func( (acc:+ num.last),  num.init)
 //)
}
else ???
}
val acc=func(Seq(), nums)
//println(acc)
var sum=0
(1 to acc.size-1).foreach{i=>
  sum += Math.abs(acc(i-1) - acc(i) )
}
println(sum)
}
