import scala.io.Source

object Main extends App {
  val lines = Source.stdin.getLines.map(_.split(" ").map(_.toInt).toList).toList
  val (rows, cols) = (lines(0)(0), lines(0)(1)+1)
  val linesOfNum: List[List[Int]] = lines.tail

  def appendSum(xs: List[Int]): List[Int] = {
    val newLine =  xs :+ xs.sum
    println(newLine.mkString(" "))
    newLine
  }


  def addEachElement(acc: List[Int], ixx: List[List[Int]]): List[Int] = ixx match {
    case Nil => acc
    case h :: tail => addEachElement((acc zip appendSum(h)).map { case (i, j) => i + j }, tail)
  }

  println(addEachElement(List.fill(cols)(0), linesOfNum).mkString(" "))
}