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

int main() {
  int n, sum, a;
  vector<int> v;

  while (cin >> n && n) {
    v.resize(n);
    for (int i=0; i<n; i++) v[i] = 0;
    for (int i=0; i<n; i++) {
      sum = 0;
      for (int j=0; j<n; j++) {
        cin >> a;
        cout << setw(5) << a;
        v[j] += a;
        sum += a;
      }
      cout << setw(5) << sum << endl;
    }
    sum = 0;
    for (int i=0; i<n; i++) {
      sum += v[i];
      cout << setw(5) << v[i];
    }
    cout << setw(5) << sum << endl;
  }

  return 0;
}