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