#include <iostream>
#include <iomanip>
using namespace std;

int main() {
	int N;

	while (cin >> N && N != 0) {
		int dataset[N+1][N+1];
        for (int i = 0; i != N; ++i) {
            for (int j = 0; j != N; ++j) {
                cin >> dataset[i][j];
            }
        }

        for (int i = 0; i != N; ++i) {
            int total = 0;
            for (int j = 0; j != N; ++j) {
                total += dataset[i][j];
            }
            dataset[i][4] = total;
        }

        for (int i = 0; i != N; ++i) {
            int total = 0;
            for (int j = 0; j != N; ++j) {
                total += dataset[j][i];
            }
            dataset[4][i] = total;
        }

        int ans = 0;
        for (int i = 0; i != N; ++i) {
            ans += dataset[4][i];      
        }
        dataset[4][4] = ans;

        for (int i = 0; i != N+1; ++i) {
            for (int j = 0; j != N; ++j) {
                cout << setw(5) << dataset[i][j];
            } 
            cout << setw(5) << dataset[i][4] << endl;
        }
	}
    return 0;
}