Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		input := make([][]int, n+1, n+1)
		totalRow := make([]int, n+1, n+1)

		for i := 0; i < n; i++ {
			row := make([]int, n+1, n+1)
			scanner.Scan()

			row = numbers(scanner.Text())

			input[i] = row
			total(totalRow, row)
		}

		input[n] = totalRow

		for xk := range input {
			for yk, yv := range input[xk] {
				if yk == n {
					fmt.Printf("%5d\n", yv)
				} else {
					fmt.Printf("%5d", yv)
				}
			}
		}
	}
}

func total(sum, row []int) {
	for i := 0; i < len(row); i++ {
		sum[i] += row[i]
	}
}

func numbers(s string) []int {
	var n []int
	var sum int
	for _, f := range strings.Fields(s) {
		i, err := strconv.Atoi(f)
		if err == nil {
			n = append(n, i)
			sum += i
		}
	}
	n = append(n, sum)
	return n
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int c[100000][11][11];
int main(){
	CLR(c);
	int cnt=0;
	vector<int>res;
	while(1){
		int N;
		cin>>N;
		if(N==0)break;
		res.PB(N);
		int sumr=0;
		REP(i,N){
			REP(j,N){
				cin>>c[cnt][i][j];
				c[cnt][i][N]+=c[cnt][i][j];
				c[cnt][N][j]+=c[cnt][i][j];
			}
			c[cnt][N][N]+=c[cnt][i][N];
		}
		cnt++;
	}
	REP(i,cnt){
		REP(j,res[i]+1){
			REP(k,res[i]+1){
				cout<<setw(5)<<right<<c[i][j][k];
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0)break;

    int x[15][15]={};
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	cin >> x[i][j];
      }
    }
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	x[i][n] += x[i][j];
	x[n][j] += x[i][j];
	x[n][n] += x[i][j];
      }
    }
    
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
	if(j < n){
	  cout.width(5);
	  cout << x[i][j];
	}
	if(j==n){
	  cout.width(5);
	  cout << x[i][j] << "\n";
	}
      }
    }
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int main(){
	int ta[100][100],sum[100];
	int n,all;
	while(cin>>n,n){
	all=0;
	for(int i=0;i<100;i++)sum[i]=0,fill(ta[i],ta[i]+100,0);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>ta[i][j];
	for(int i=0;i<n;i++){
		int tnow=0;
		for(int j=0;j<n;j++){
		cout<<ta[i][j]<<" ";
		sum[i]+=ta[i][j];
		tnow+=ta[i][j];
		all+=ta[i][j];
		}
		cout<<tnow<<endl;
	}
	for(int i=0;i<n;i++)cout<<sum[i]<<" ";
	cout<<all<<endl;
	}

	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;

int main(){
	int n;
	while(1){
	cin>>n;
		if(n==0)break;
	vector<vector<int> > a(n+1,vector<int>(n+1));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	
	for(int i=0;i<n;i++){
		int b=0;
		for(int j=0;j<n;j++){
			cout<<"  "<<a[i][j]<<" ";
			b+=a[i][j];
		}
		cout<<b<<endl;
	}
	
	int d=0;
	
	for(int i=0;i<n;i++){
		int c=0;
		for(int j=0;j<n;j++){
			c+=a[j][i];
		}
		cout<<" "<<c<<" ";
		d+=c;
	}
	cout<<d<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11] = {0};
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n; j++)
				a[i][n] += a[i][j];
			a[n][n] += a[i][n];
		}

		for (j = 0; j < n; j++)
			for (i = 0; i < n; i++)
				a[n][j] += a[i][j];

		for (i = 0; i <= n; i++)
		{
			for (j = 0; j <= n; j++)
				printf("%5d", a[i][j]);
			printf("\n");
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int n;
	while(cin>>n,n!=0){
		int a[n+1][n+1];
		for(int i=0;i<n;i++){
			a[n][i]=0;a[i][n]=0;
		}
		a[n][n]=0;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>a[i][j];
				//cout<<a[i][j]<<" ";
				a[i][n]+=a[i][j];
				a[n][j]+=a[i][j];
			}
			//cout<<endl;
		}
		
		for(int i=0;i<n;i++)a[n][n]+=a[n][i];
		
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
			printf("%5d",a[i][j]);
			}
			cout<<endl;
		}
		
	}

}

C++: #include<iostream>
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
				else if(dt[a][b]/100000==0)cout<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#define rep(i, n) for(i=0;i<(n);++i)
int a[11][11], n, i, j, t;
int main()
{
    while (scanf("%d", &n), n) {
        memset(a, 0, sizeof(a));
        rep(i, n) rep(j, n) {
            scanf("%d", &t); a[i][j] = t; a[n][j] += t; a[i][n] += t;
        }
        rep(i, n) a[n][n] += a[i][n];
        rep(i, n+1) {
            rep(j, n+1) printf("%5d", a[i][j]);
            puts("");
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n;
int tb[11][11];

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			int rsum = 0;
			for (int j = 0; j < n; j++) {
				cin >> tb[i][j];
				rsum += tb[i][j];
			}
			tb[i][n] = rsum;
			allsum += rsum;
		}
		tb[n][n] = allsum;
		
		for (int j = 0; j < n; j++) {
			int csum = 0;
			for (int i = 0; i < n; i++) {
				csum += tb[i][j];
			}
			tb[n][j] = csum;
		}
		
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << tb[i][j];
			}
			cout << endl;
		}
	}	
	
	return 0;
}