#include<iostream>
#include<cstring>
using namespace std;
int x[10000][10000], n;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> x[i][j]; x[i][n] += x[i][j]; x[n][j] += x[i][j]; x[n][n] += x[i][j];
			}
		}
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << x[i][j] << endl;
			}
		}
	}
}