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++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

void solve(VVI &in, int n){
	int rowSum = 0, columnSum = 0;
	int allSum=0;
	FOR(i, 0, in.size()-1){
		rowSum = 0;
		columnSum = 0;
		FOR(j, 0, in[i].size()-1){
			rowSum += in[i][j];
			columnSum += in[j][i];
		}
		allSum += rowSum;
		in[i][n] = rowSum;
		in[n][i] = columnSum;
	}
	in[n][n] = allSum;
	FOR(i, 0, in.size()){
		FOR(j, 0, in[i].size()){
			printf("%5d", in[i][j]);
			if (j < in[i].size() - 1)
				printf(" ");
		}
		puts("");
	}
}

int main(){
	int n, in = 0;
	while (cin >> n, n){
		VVI inNum(n + 1, VI(n + 1));
		FOR(i, 0, n){
			FOR(j, 0, n){
				cin >> in;
				inNum[i][j] = in;
			}
		}
		solve(inNum,n);
	}
	return 0;
}

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

int main(){
    int n;
    while( cin >> n, n ){
        long long sheet[n+1][n+1];
        int i, j;
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                cin >> sheet[i][j];
            }
        }
        int ss = 0;
        for(i = 0; i < n; i++){
            int s = 0;
            for(j = 0; j < n; j++){
                s += sheet[i][j];
            }
            sheet[i][n] = s;
            ss += s;
        }
        sheet[n][n] = ss;
        for(i = 0; i < n; i++){
            int s = 0;
            for(j = 0; j < n; j++){
                s += sheet[j][i];
            }
            sheet[n][i] = s;
        }
        for(i = 0; i <= n; i++){
            printf("%5lld", sheet[i][0]);
            for(j = 1; j <= n; j++){
                printf("%5lld", sheet[i][j]);
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n[127], tn=0,ni=0,all = 0, i = 0;
	int data[512][256];
	int tdata[256] = { 0 };
	
		//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];
		ni++;

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
	}
	

	//output
	for (int k = 0; k < ni; k++){
		for (int i = 0; i < tn; i++, all = 0){
			for (int j = 0; j < n[k]; j++){
				printf(" %3d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf(" %3d\n", all);
		}

		all = 0;
		for (int i = 0; i < n[k]; i++){
			printf(" %3d", tdata[i]);
			all += tdata[i];
		}
		printf(" %3d\n", all);
	}
	return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

int main() {
    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == 0) return 0;
        vector<vector<int> > a(n+1, vector<int>(n+1, 0));
        rep (i, n) rep (j, n) scanf("%d", &a[i][j]);
        rep (i, n) rep (j, n) a[n][i] += a[j][i];
        rep (i, n+1) rep (j, n) a[i][n] += a[i][j];
        rep (i, n+1) {
            rep (j, n+1) printf("%5d", a[i][j]);
            printf("\n");
        }
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,data[11][11];
  while(1){
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	data[i][j]=0;
      }
    }
    cin>>n;
    if(n==0){break;}
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>data[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	data[i][n]+=data[i][j];
	data[n][i]+=data[j][i];
	data[n][n]+=data[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	cout<<data[i][j];
	if(j!=n){
	cout<<" ";
	}
      }
      cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int matrix[11][11];

int main()
{
	int n,sum;
	
	for(;;)
	{
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin>>matrix[i][j];
			}
		}

		for(int i=0;i<n;i++)
		{
			sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=matrix[i][j];
			}
			matrix[i][n]=sum;
		}
		for(int j=0;j<n;j++)
		{
			sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=matrix[i][j];
			}
			matrix[n][j]=sum;
		}
		sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=matrix[i][n];
		}
		matrix[n][n]=sum;
		
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				cout<<setfill(' ')<<setw(5)<<right<<matrix[i][j];
			}
			cout<<endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n,n){
		int data[101][101] = {0};
		rep(i,n)rep(j,n)
			cin >> data[i][j] , data[n][n] += data[i][j];
		rep(i,n){
			int s = 0;
			rep(j,n) s+= data[i][j];
			data[i][n] = s;
		}
		rep(i,n){
			int s = 0;
			rep(j,n) s+= data[j][i];
			data[n][i] = s;
		}
		rep(i,n+1){
			rep(j,n+1)
				printf("%5d",data[i][j]);
			cout << endl;
		}
	}
}

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

int main(){
	int n, h[11][11];
	while(scanf("%d", &n)){
		if(!n)break;
		for(int i = 0;i < n;i++){
			int num = 0;
			for(int j = 0;j < n;j++){
				scanf("%d", &h[i][j]);
				num += h[i][j];
				printf("%5d", h[i][j]);
			}
			h[i][n] = num;
			printf("%5d\n", num);
		}
		
		for(int i = 0;i <= n;i++){
			int num = 0;
			for(int j = 0;j < n;j++)num += h[j][i];
			printf("%5d", num);
		}
	}
}

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

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				if(table[i][j] / 100 != 0) cout << "  ";
				else cout << "   ";
				cout << table[i][j];
			}
			if(i + 1 != n)cout << "\n";
		}
	}
	return 0;
}