#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>

int main() {
  int n;
  while(cin >>n && n){
    vector< vector<int> > v(n, vector<int>(n));
    REP(i, n) REP(j, n) cin >>v[i][j];
    REP(i, n){
      v[i].push_back(accumulate(v[i].begin(), v[i].end(), 0));
      REP(j, v[i].size()){
        printf("%5d", v[i][j]);
      }
      cout <<endl;
    }
    int ss = 0;
    REP(j, n){
      int s = 0;
      REP(i, n) s += v[i][j];
      printf("%5d", s);
      ss += s;
    }
    printf("%5d", ss);
    cout <<endl;
  }
  return 0;
}