#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n,all=0;
	int data[512][512];
	int tdata[512] = { 0 };
	
	while (1){
		//input
		cin >> n;
		if (n == 0)break;

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		//output

		for (int i = 0; i < n; i++, all = 0){
			for (int j = 0; j < n; j++){
				printf(" %d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf(" %d\n", all);
		}

		all = 0;
		for (int i = 0; i < n; i++){
			printf(" %d", tdata[i]);
			all += tdata[i];
		}
		printf(" %d\n", all);
	}
	return 0;
}