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

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    int n;
    while ((n = readint()) > 0) {
        auto xs = new int[][](n + 1, n + 1);
        for (int i = 0; i < n; i++) {
            auto ys = readints();
            for (int j = 0; j < n; j++) {
                xs[i][j] = ys[j];
            }
        }

        // ?????????
        for (int c = 0; c < n; c++) {
            int sum = 0;
            for (int r = 0; r < n; r++) {
                sum += xs[r][c];
            }
            xs[n][c] = sum;
        }

        // ?¨???????
        for (int r = 0; r < n + 1; r++) {
            int sum = 0;
            for (int c = 0; c < n; c++) {
                sum += xs[r][c];
            }
            xs[r][n] = sum;
        }

        // ??????
        for (int r = 0; r < n + 1; r++) {
            for (int c = 0; c < n + 1; c++) {
                writef("%5d", xs[r][c]);
            }
            writeln();
        }
    }
}