r,c = gets.split.map(&:to_i)

h = []
r.times do
  h << gets.split.map(&:to_i)
end

h.each{|x| x << x.inject(&:+)}
h = h.transpose.each{|x| x << x.inject(&:+)}.transpose

puts h.map{|x| x.join ' '}.join "\n"