object Main extends App {
	override def main(args: Array[String]){
		val sc = new java.util.Scanner(System.in)
		
		val h = sc.nextInt
		val w = sc.nextInt
		
		val s = new SpreadSheet(h,w);
		for(i <- (0 until h) ; j <- (0 until w)){
			s(i,j) = sc.nextInt
		}
		s calc
		
		for(i <- (0 to h); j<- (0 to w)){
			print(s(i,j) +" ")
			if(j == w){
				println
			}
		}
	}
	
}

class SpreadSheet(val h: Int , val w :Int){
	val matrix = Array.ofDim[Int](h+1,w+1)
	def update(i:Int , j:Int , newValue:Int):Unit = {
		matrix(i)(j) = newValue
	}
	def apply(i:Int,j:Int): Int = matrix(i)(j)
	
	def calc:Unit = {
		for(i <- (0 until h) ; j <- (0 until w)){
			matrix(h)(w) = matrix(h)(w) + matrix(i)(j)
			matrix(h)(j) = matrix(h)(j) + matrix(i)(j)
			matrix(i)(w) = matrix(i)(w) + matrix(i)(j)
		}
	}
}