while str = STDIN.gets
    n = str.to_i
    exit 0 if n == 0

    array = Array.new(n+1)
    for i in 0..n do
        array[i] = Array.new(n+1)
    end

    for i in 0..n-1 do
        str = STDIN.gets.chomp
        l = str.split
        for j in 0..n-1 do
            array[i][j] = l[j].to_i
        end
    end

    for i in 0..n-1 do
        sum_col = 0
        sum_row = 0
        for j in 0..n-1 do
            sum_col = sum_col + array[i][j]
            sum_row = sum_row + array[j][i]
        end
        array[i][n] = sum_col
        array[n][i] = sum_row
    end

    sum_total = 0
    for i in 0..n-1 do
        sum_total = sum_total + array[i][n]
    end
    array[n][n] = sum_total

    for i in 0..n do
        for j in 0..n do
            printf "%5d", array[i][j]
        end
        print "\n"
    end
end