while true
	n = gets.chomp.to_i
	break if n == 0
	a = Array.new(n, 0)
	n.times do
		b = gets.chomp.split("\s").map {|v| v.to_i}
		x = 0
		b.each_with_index do |v, i|
			printf("%5d", v)
			x = x + v
			a[i] = a[i] + v
		end
		printf("%5d\n", x)
	end
	x = 0
	a.each do |v|
		printf("%5d", v)
		x = x + v
	end
	printf("%5d\n", x)
end