while n = gets
n = n.chomp.to_i
break if n == 0
ary = []
ary2 = Array.new(n+1,0)
n.times do
line = gets.split.map(&:to_i)
tmp = 0
for i in 0..(n-1)
  tmp += line[i]
  end
line << tmp
ary << line
end

for i in 0..(n-1)#3
  for j in 0..n #0..4
    ary2[j] += ary[i][j]
  end
end

ary << ary2
ary.each do |i|
  i.each do |j|
    printf("%5d",j)
  end
  puts
end
end
