a=gets.split(" ").map{|e|e.to_i}
sum=Array.new(a[1],0)
a[0].to_i.times{
	l=gets.split(" ").map{|e|e.to_i}
	puts "#{l*" "} #{l.inject(:+)}"
	sum=[sum, l].transpose.map{|f|f.inject(:+)}
}
puts "#{sum*" "} #{sum.inject(:+)}"