#coding: utf-8
#AOJ vol1-0102

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