import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main(){
    int N;
    while((N = readln.chomp.to!int, N)){
        int[] sum = new int[N];
        foreach(i; 0..N){
            int[] data = readln.chomp.split.map!(to!int).array;
            sum[] += data[];
            data.map!(a => (writef("%5d", a), 0)).array;
            writefln("%5d", data.reduce!"a + b");
        }
        sum.map!(a => (writef("%5d", a), 0)).array;
        writefln("%5d", sum.reduce!"a + b");
    }
}