import scala.collection.mutable.ArrayBuffer
import scala.math.abs

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = Seq.fill(n)(sc.nextInt).sortWith((x, y) => x < y)
    val (lowers, highers) = if (n % 2 == 0) {
      (xs.take(n / 2), xs.drop(n / 2))
    } else {
      (xs.take((n - 1) / 2), xs.drop((n - 1) / 2))
    }
    val answer = highers.sum - lowers.sum
    println(answer)

    var ys = ArrayBuffer.empty[Int]
    for (i <- 0 until lowers.size) yield {
      ys += highers(i)
      ys += lowers(i)
    }
    if (n % 2 != 0) {
      ys += highers.last
    }
    if (n % 2 == 0) {
      ys = ys.reverse
    }

    var tmp: Option[Int] = None
    for (i <- 1 until ys.size) {
      if (tmp.isEmpty) {
        println(s"${ys(i)} ${ys(i - 1)}")
        tmp = Some(ys(i) - ys(i - 1))
      } else {
        println(s"${ys(i)} ${tmp.get}")
        tmp = Some(ys(i) - tmp.get)
      }
    }
  }
}
