object Main extends App {
  val n = StdinReader.nextInt
  val as = (1 to n).map(i => StdinReader.nextInt).sorted.toArray
  def sum(begin: Int, end: Int) = (begin to end).map(i => as(i)).sum

  val m = n / 2
  println(if (n % 2 == 1) {
    (sum(m + 2, n - 1) * 2 + as(m + 1)) - (sum(0, m - 2) * 2 + as(m - 1)) +
    Math.max(as(m + 1) - as(m), as(m) - as(m - 1))
  } else {
    (sum(m + 1, n - 1) * 2 + as(m)) - (sum(0, m - 2) * 2 + as(m - 1))
  })
}

object StdinReader {
  val is = System.in
  val buffer = new Array[Byte](1024 * 1024)
  var size = 0
  var pos = 0

  private def readByte: Byte = {
    if (pos >= size) {
      pos = 0;
      size = is.read(buffer);
    }
    if (size < 0) -1
    else {
      val ret = buffer(pos)
      pos += 1
      ret
    }
  }

  // support single byte char only
  def next: String = {
    @scala.annotation.tailrec
    def r(sb: StringBuilder, reading: Boolean): String = {
      readByte match {
        case b if ('!' <= b && b <= '~') => r(sb.append(b.asInstanceOf[Char]), true)
        case _ => if (reading) sb.toString else r(sb, false)
      }
    }
    r(new StringBuilder, false)
  }

  def nextInt: Int = {
    @scala.annotation.tailrec
    def r(i: Int, reading: Boolean): Int = {
      readByte match {
        case '-' => r(i * -1, true)
        case b if '0' <= b && b <= '9' => r(i * 10 + (b - '0'), true)
        case _ => if (reading) i else r(i, false)
      }
    }
    r(0, false)
  }
}