module AOJ_Volume0102;

import std.stdio,std.string,std.conv;

int main()
{
	int a[101][101];
	while(true)
	{
		int n = readln.chomp.to!int;
		if(n == 0) break;

		foreach(i;0..n)
		{
			string[] s = readln.chomp.split(" ");
			foreach(j;0..s.length)
			{
				a[i][j] = s[j].to!int;
			}
		}

		int sum_n = 0;
		foreach(i;0..n)
		{
			int sum = 0;
			int sum_2 = 0;
			foreach(j;0..n)
			{
				sum += a[i][j];
				sum_2 += a[j][i];
			}
			a[i][n] = sum;
			a[n][i] = sum_2;

			sum_n = a[i][n];
		}

		foreach(i;0..n+1)
		{
			foreach(j;0..n+1)
			{
				writef("%5d",a[i][j]);
			}
			writeln;
		}
	}
	return 0;
}