while true
    n = gets.to_i
    break if n == 0
    arr = Array.new(n + 1, 0)
    n.times{
        line = gets.chomp.split.map(&:to_i)
        line << line.inject(:+)
        (n + 1).times{|i|
            print sprintf("%5d", line[i])
            arr[i] += line[i]
        }
        puts
    }
    (n + 1).times{|i| print sprintf("%5d", arr[i])}
    puts
end
