#include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin >> n && n){
		std::vector<std::vector<int> > vec(n+1,std::vector<int>(n+1));
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				std::cin>>vec[i][j];
				sum+=vec[i][j];
			}
			vec[i][n]=sum;
		}
		for(int i = 0; i < n+1; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				sum+=vec[j][i];
			}
			vec[n][i]=sum;
		}
		for(int i = 0; i < n+1;++i){
			for(int j = 0; j < n+1; ++j){
				std::cout<<vec[i][j];
				if(j!=n)std::cout<<" ";
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}