'use strict'

function Main(input) {
  const N = Number(input.split("\n")[0])
  // const A = input.split(" ").slice(1, N)
  const B = input.split("\n")[N].split(" ").map(x => Number(x))

  const M = B.reduce((acc, x) => acc + x) - Math.max(...B)
  console.log(M)
  B.sort((a, b) => b - a)
  console.log(B.join(" "))
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())
