#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<deque>
using namespace std;

string convert(int x){
	stringstream buf;
	buf<<x;
	while(buf.str().size()<5){
		string tmp = buf.str();
		buf.str("");
		buf<<" "<<tmp;
	}
	return buf.str();
}

int main(){
	int n;
	cin>>n;
	stringstream buf;
	while(n!=0){
		vector< vector<int> > table;
		for(int x=0;x<n;++x){
			vector<int> tmp;
			int sum = 0;
			for(int i=0;i<n;++i){
				int j;cin>>j;
				tmp.push_back(j);
				sum +=j;
			}
			tmp.push_back(sum);
			table.push_back(tmp);	
		}
		vector<int> tmp;
		for(int x=0;x<table[0].size();++x){
			int sum = 0;
			for(int y=0;y<table.size();++y){
				sum += table[y][x];
			}
			tmp.push_back(sum);
		}
		table.push_back(tmp);

		for(int x=0;x<table.size();++x){
			for(int y=0;y<table[x].size();++y){
				buf<<convert(table[x][y]);
			}
			buf<<"\n";
		}
		cin>>n;
	}
	cout<<buf.str();
	return 0;
}