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))
  val linesOfNum: List[List[Int]] = lines.tail


  val newLines: List[Int] = for {
                              line <- linesOfNum
                            } yield { val str = line.mkString(" ")
                                println(s"$str ${line.sum}")
                                line.sum
                            }

  // non-tail-recursive
  def addEachElement(ixx: List[List[Int]]): List[Int] = ixx match {
    case Nil => List(0, 0, 0, 0, 0)
    case h :: tail => (h zip addEachElement(tail)).map { case (i, j) => i + j }
  }

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

  println(addEachElement(linesOfNum).mkString(" ") + " " + newLines.sum)
  // println(addEachElement(List(0, 0, 0, 0, 0), linesOfNum))
}