/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_C
  * Structured Program II - Spreadsheet
  */
object Main {
  def main(args: Array[String]): Unit = {
    val Array(r, c) = io.StdIn.readLine().split(" ").map(_.toInt)
    val initial = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(r)
      .map(_.split(" ").map(_.toInt).toSeq)
      .toVector
    val columnComputed = initial.map(row => row :+ row.sum)
    val fullComputed = columnComputed :+ columnComputed.foldLeft(Seq.empty[Int]) {
      (acc, x) => acc.zipAll(x, 0, 0).map { case (a, b) => a + b }
    }
    fullComputed.foreach(row => println(row.mkString(" ")))
  }
}