r, c = gets.split(" ").map(&:to_i)
array = Array.new(r).map{ Array.new(c) }

for i in 0..(r - 1)
  array[i] = gets.split(" ").map(&:to_i)
  array[i].push(array[i].inject(:+))
end

array = array.transpose

for i in 0..c
  array[i].push(array[i].inject(:+))
end

for i in 0..r
  puts array.transpose[i].to_s.gsub(/[\[\]\,]/, "")
end