
import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;

string fmt(int n) {return format("%5d", n);}
string join_num(int[] arr) {return arr.map!(fmt).join("");}
void show(int[] arr) {writeln(arr.join_num, "", arr.reduce!("a + b").fmt);}

void main() {
  int times;
  while((times = readln.chomp.to!(int)) != 0) {
    int[] cols = new int[](times);
    foreach(t; 0..times) {
      int[] arr = readln.chomp.split(" ").map!((x) => x.to!(int)).array;
      foreach(int i, ref c; cols) c += arr[i];
      show(arr);
    }
    show(cols);
  }
}