#include <bits/stdc++.h>
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0583

template<typename T>
vector< T > divisor(T n) {
  vector< T > ret;
  for(T i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

template<typename T>
T gcd(T a, T b){
    if (b==0) return a;
    else return  gcd(b,a%b);
}




int main(){
    int n;
    int a,b,c;
    cin >> n;
    vector<int> ret;
    if (n==2){
        cin >> b >> c;
        int a = gcd<int>(b,c);
        ret = divisor<int>(a);
    }else if (n==3){
        cin >> a >> b >> c;
        int k = gcd<int>(a,gcd<int>(b,c));
        ret = divisor<int>(k);
    }
    for(const int &p :ret){
        printf("%d\n",p);
    }
    
}

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int stage[12][12] = {{0}};
    int n;
    int j = 0;
    int x = 0,y = 0,xx = 0;
    for(;;){
        cin >> n;
        if(n == 0)break;
        for(int i = 0;i < n; i++){
            for(j = 0;j < n; j++){
                cin >> stage[i][j];
                x += stage[i][j];
                if(j == n-1){
                    stage[i][n] = x;
                    xx += stage[i][n];
                    x = 0;
                }
            }
        }
        for(int i = 0;i < n; i++){
            for(j = 0;j < n; j++){
                y += stage[j][i];
                if(j == n-1){
                    stage[n][i] = y;
                    y = 0;
                }
            }
        }
        stage[n][n] = xx;
        for(int i = 0;i <= n; i++){
            for(int j = 0;j <= n; j++){
                printf("%5d",stage[i][j]);
            }
            printf("\n");
        }
        x = 0,y = 0,xx = 0;
    }
    return 0;
}