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++: //Name: Matrix-like Computation
//Level: 1
//Category: やるだけ
//Note:

#include <iostream>
#include <vector>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<vector<int>> v(N+1, vector<int>(N+1, 0));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            cin >> v[i][j];
            v[i][N] += v[i][j];
            v[N][j] += v[i][j];
            v[N][N] += v[i][j];
        }
    }
    for(int i = 0; i < N+1; ++i) {
        for(int j = 0; j < N+1; ++j) {
            cout.width(5);
            cout << v[i][j] << ends;
        }
        cout << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s[n+1][n+1];
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	cin >> s[i][j];
	a += s[i][j];
      }
      s[i][n] = a;
    }
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	a += s[j][i];
      }
      s[n][i] = a;
    }
    int a = 0;
    for(int i=0;i<n;i++) a += s[n][i]; 
    s[n][n] = a;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	if(s[i][j]>=10000) cout << s[i][j] << endl;
	else if(s[i][j]>=1000) cout << " " << s[i][j];
	else if(s[i][j]>=100) cout << "  " << s[i][j];
	else if(s[i][j]>=10) cout << "   " << s[i][j];
	else if(s[i][j]>=1) cout << "    " << s[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s[n+1][n+1];
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	cin >> s[i][j];
	a += s[i][j];
      }
      s[i][n] = a;
    }
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	a += s[j][i];
      }
      s[n][i] = a;
    }
    int a = 0;
    for(int i=0;i<n;i++) a += s[n][i]; 
    s[n][n] = a;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	if(s[i][j]>=10000) cout << s[i][j];
	else if(s[i][j]>=1000) cout << " " << s[i][j];
	else if(s[i][j]>=100) cout << "  " << s[i][j];
	else if(s[i][j]>=10) cout << "   " << s[i][j];
	else if(s[i][j]>=0) cout << "    " << s[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

void calculate(int const n);
void show_table(const vector<int> table, const int n);

int main()
{
	int n = 0;

	while(true) {
		cin >> n;
		if(n==0) break;
		calculate(n);
	}

	return 0;
}

void calculate(int const n)
{
	int row_n = n+1;
	vector<int> table((row_n)*(row_n),0);

	// 表への入力
	for(int i=1;i<=row_n*n;i++) {
		if(i%row_n==0) ;			//  結果が入るところはスキップ
		else
			cin >> table[i-1];
	}
	cout << "ok1\n";

	// 右側の和の計算 
	for(int i=n;i<=(row_n)*(row_n);i+=(row_n))
		for(int j=1;j<=n;j++)
			table[i] += table[i-j];

	// 下側の和の計算
	int count = 0;
	int j = 0;
	for(int i=0;i<n;i++) {
		count = 0;
		j = i;
		while(true) {
			table[(row_n)*n+i] += table[j];
			j += (row_n);
			count++;
			if(count==n) break;
		}
	}
	// 右下の和の計算
	for(int i=n;i<(row_n)*n;i+=(row_n))
		table[(row_n)*(row_n)-1] += table[i];

	show_table(table,n);
}

void show_table(const vector<int> table,const int n)
{
	int row_n = n+1;
	for(int i=0;i<(row_n)*(row_n);i+=(row_n)) {
		for(int j=i;j<i+row_n;j++)
			cout << setw(5) << table[j];
		cout << endl;
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	int n, a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			cout << a[i][j] << " ";
			sum_h[i] += a[i][j];
			sum_v[j] += a[i][j];
		}
		sum_v[n] += sum_h[i];
		cout << sum_h[i] << endl;
	}
	for (int i = 0; i < n; i++)
		cout << sum_v[i] << " ";
	cout << sum_v[n] << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (true) {
        cin >> n;
        if (!n) {
            break;
        }
        vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][n] += v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[n][i] += v[j][i];
            }
            v[n][n] += v[n][i];
        }
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                cout << setw(5) << v[i][j] << ' ';
            }
            cout << '\n';
        }
    }
}

C++: #include<stdio.h>

int a[1000][1000],i,j,n;

int main(){
    scanf("%d",&n);
    while(n!=0){
        a[n][n]=0;
        for(i=0;i<n;i++){
            a[i][n]=0;
            a[n][i]=0;
            for(j=0;j<n;j++){
                scanf("%d",&a[i][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+1;i++){
            for(j=0;j<n+1;j++){
                printf("% 5d",a[i][j]);
            }
            printf("\n");
        }
    }
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s[n+1][n+1];
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	cin >> s[i][j];
	a += s[i][j];
      }
      s[i][n] = a;
    }
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	a += s[j][i];
      }
      s[n][i] = a;
    }
    int a = 0;
    for(int i=0;i<n;i++) a += s[n][i]; 
    s[n][n] = a;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	if(s[i][j]>=10000) cout << s[i][j] << endl;
	else if(s[i][j]>=1000) cout << " " << s[i][j];
	else if(s[i][j]>=100) cout << "  " << s[i][j];
	else if(s[i][j]>=10) cout << "   " << s[i][j];
	else if(s[i][j]>=0) cout << "    " << s[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}