import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	int n;
	while (n = readln.chomp.to!int, n) {
		auto tbl = new int[][](n+1, n);
		foreach (i; 0..n) {
			auto x = readln.split.map!(to!int).array;
			x ~= x.reduce!("a+b");
			foreach (j; 0..n+1) {
				writef("%5d", x[j]);
				tbl[j][i] = x[j];
			}
			writeln("");
		}
		foreach (i; 0..n+1) {
			writef("%5d", tbl[i].reduce!("a+b"));
		}
		writeln("");
	}
}