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");
			x.map!(to!string).join(" ").writeln;
			foreach (j; 0..n+1) {
				tbl[j][i] = x[j];
			}
		}
		auto res = new int[](n+1);
		foreach (i; 0..n+1) {
			res[i] = tbl[i].reduce!("a+b");
		}
		res.map!(to!string).join(" ").writeln;
	}
}