while 0 != data = gets.to_i do
	under = Array.new(data+1){0}
	data.times do
		sum = 0
		num = gets.split(" ").map!(&:to_i)
		num.each_with_index do |x,i|
			print " " * (5 - x.to_s.length) + x.to_s
			sum = sum + x
			under[i] += x
		end
		under[data] += sum
		puts " " * (5 - sum.to_s.length) + sum.to_s
	end
	under.each do |x|
		print " " * (5 - x.to_s.length) + x.to_s
	end
	puts ""
end