n = gets.to_i
until n == 0
    tate = Array.new(n,0)
    n.times do
        x = gets
        y = x.split(" ")
        z = y.map{|a| a.to_i}
        yokosum = z.sum
        i = 0
        while i < n
            tate[i] += z[i]
            i += 1
        end
        z << yokosum
        wwans1 = z.map{|w| w.to_s}
        wans1 = wwans1.map{|w| w.rjust(5," ")}
        ans1 = wans1.join
        puts ans1
    end
    tatesum = tate.sum
    tate << tatesum
    wwans2 = tate.map{|w| w.to_s}
    wans2 = wwans2.map{|w| w.rjust(5," ")}
    ans2 = wans2.join
    puts ans2
    n = gets.to_i
end

