#!/usr/bin/env ruby

if __FILE__ == $0 then
	r, c = gets.split.map(&:to_i)

	bottom = [0]*c
	r.times do
		s = gets.chomp
		n = s.split.map(&:to_i)
		puts '%s %d' % [s, n.sum]
		c.times do |j|
			bottom[j] += n[j]
		end
	end
	puts '%s %d' % [bottom.map(&:to_s).join(' '), bottom.sum]
end

