rows=[]
(n=gets.chomp.split.map(&:to_i))[0].times{
rows<< (m=gets.split.map(&:to_i)).push(m.inject(:+))
}
me=Array.new((n[1]+1),0)
(n[1]+1).times{|a|;(n[0]).times{|b|me[a]+=rows[b][a]}}
rows.map{|ans|puts ans.join(" ")};puts me.join(" ")
