loop do
	data = gets.to_i 
	break if data == 0
	under = Array.new(data+1){0}
	data.times do
		sum = 0
		num = gets.split(" ").map!(&:to_i)
		num.each_with_index do |x,i|
			printf "%5d",x
			sum = sum + x
			under[i] += x
		end
		under[data] += sum
		printf "%5d",sum
		puts ""
	end
	under.each do |x|
		printf "%5d",x
	end
	puts ""
end