#include <iostream>

using namespace std;

int main(void){
    while(true) {
        int n;
        cin >> n;
        if (n == 0) break;
        int cell[n+1][n+1];
        int sum_r, sum_c;
        for (int i = 0; i < n; i++) {
            sum_r = 0;
            for (int j = 0; j < n; j++) {
                cin >> cell[i][j];
                sum_r += cell[i][j];
            }
            cell[i][n] = sum_r;
        }
        for (int i = 0; i <= n; i++) {
            sum_c = 0;
            for (int j = 0; j < n; j++) {
                sum_c += cell[j][i];
            }
            cell[n][i] = sum_c;
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                cout << cell[i][j];
                if (j < n) cout << " ";
            }
            cout << endl;
        }
    }
    return 0;
}