object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt)).toSeq.tail
    val x = in.map(r => r :+ r.sum)
    val y = x.transpose.map(_.sum)
    x.foreach(r => println(r.mkString(" ")))
    println(y.mkString(" "))
}