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

using namespace std;

int main(){
	int n;
	int x[12][12];
	
	while (cin >> n){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				cin >> x[i][j];
			}
		}
	}
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			x[i][n + 1] += x[i][j];
		}
	}
	for (int j = 1; j <= n; j++){
		for (int i = 1; i <= n; i++){
			x[n + 1][j] += x[i][j];
		}
	}
	for (int i = 1; i <= n + 1; i++){
		for (int j = 1; j <= n + 1; j++){
			printf("%5d\n", x[i][j]);
		}
	}
	return 0;
}