#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	int **p;
	int n;
	while (cin >> n && n) {
		p = new int*[n+1];
		for (int i = 0; i < n + 1; i++)
			p[i] = new int[n+1];
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				cin >> p[i][j];
				sum += p[i][j];
			}
			p[i][n] = sum;
		}
		for (int j = 0; j < n + 1; j++) {
			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += p[i][j];
			}
			p[n][j] = sum;
		}
		for (int i = 0; i < n + 1; i++) {
			for (int j = 0; j < n + 1; j++) {
				cout.width(5);
				cout << p[i][j];
			}
			cout << endl;
		}
		for (int i = 0; i < n + 1; i++)
			delete[] p[i];
		delete[] p;
	}
	return 0;
}