#coding: utf-8
#AOJ vol1-0102

loop do
  n = gets.to_i
  break if n == 0
  data = Array.new(5,0)
  n.times.each{
    sum = 0
    input = gets.chomp.split.map{|i|i.to_i}
    input.size.times.each{|j|
      data[j] += input[j]
      sum += input[j]
    }
    data[4] += sum
    input.each{|t| print(sprintf("% 5d",t))}
    puts sprintf("% 5d",sum)
  }
  data.each{|t| print(sprintf("% 5d",t))}
  puts ""
end