#include <iostream>
#include <math.h>
using namespace std;
int main() {
	int n, a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			cout << a[i][j] << " ";
			sum_h[i] += a[i][j];
			sum_v[j] += a[i][j];
		}
		sum_v[n] += sum_h[i];
		cout << sum_h[i] << endl;
	}
	for (int i = 0; i < n; i++)
		cout << sum_v[i] << " ";
	cout << sum_v[n] << endl;
	return 0;
}
