import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    while( {n=readInt;n} != 0 ) {
      val l = new ArrayBuffer[Array[Int]]
      val sum = new Array[Int](n+1)
      for(i<-1 to n) {
        val s = readLine.split(" ").map(_.toInt)
        l += s :+ s.sum
        (0 until n).foreach ( i => sum(i) += s(i) )
      }
      sum(n) = l.toArray.map(e=>e(n)).sum
      println(l.toArray.map(_.map("%5d".format(_)).mkString(" ")).mkString("\n"))
      println(sum.map("%5d".format(_)).mkString(" "))
    }
  }
}