class Array
  def +(other)
    zip(other).map {|x, y| x + y }
  end
end
m, n = gets.split.map(&:to_i)
a = (1..m).map { gets.split.map(&:to_i) }
a << a.inject(:+).dup
a.each do |row|
  row << row.inject(:+)
  puts row * " "
end
