object Main extends App {
  val n = readInt
  val ints = (1 to n).map(_ => readInt)
  val (smallerInts, largerInts) = ints.sorted.splitAt(ints.length / 2)
  println(largerInts.head.toLong - smallerInts.last.toLong - smallerInts.init.sum[Long] * 2 + largerInts.tail.sum[Long] * 2)
}