Go: package main

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

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

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	while (cin >> n, n){
		vector<vector<int>> hyou(n + 1, vector<int>(n + 1, 0));
		REP(i, n){
			REP(j, n){
				int num;
				cin >> num;
				hyou[i][j] = num;
			}
		}
		REP(i, n){
			REP(j, n){
				hyou[i][n] += hyou[i][j];
			}
		}
		REP(j, n){
			REP(i, n){
				hyou[n][j] += hyou[i][j];
			}
		}
		REP(i, n){
			hyou[n][n] += hyou[i][n];
		}
		REP(i, n + 1){
			REP(j, n + 1){
				printf("%5d", hyou[i][j]);
			}
			printf("\n");
		}
	}
}

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

using namespace std;

int main() {
    
    int n;
    while (cin >> n) {
    
    if(n == 0)
    break;
    
    int A[51][51] = {};
    
    for(int i=0;i<n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cin >> A[i][j];
    	
    	A[i][n] += A[i][j];
    	A[n][j] += A[i][j];
	}
	A[n][n] += A[i][n];
}

	for(int i=0;i<=n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cout << setw(5)<< A[i][j];
    }
	cout << setw(5)<< A[i][n];
	cout << "\n";
}
}
    return 0;
}

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

int a[11][11];

void init() {
  for(int i = 0; i < 11; ++i) {
	for(int j = 0; j < 11; ++j) {
	  a[i][j] = 0;
	}
  }
}

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

void print(int n) {
  for(int i = 0; i <= n; ++i) {
	for(int j = 0; j <= n; ++j) {
	  cout << right << setw(5) << a[i][j];
	  cout << (j < n ? " " : "\n");
	}
  }
}

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

	init();
	for(int i = 0; i < n; ++i) {
	  for(int j = 0; j < n; ++j) {
		cin >> a[i][j];
	  }
	}
	Comp(n);
	print(n);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#define MAX_N 110
using namespace std;
int main(){
	int n,i,j;
	int a[MAX_N][MAX_N];
	while(1){
		cin >> n;
		if(n==0)break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				cin >> a[i][j];
			}
		}

		int sum1=0,sum[MAX_N];
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				sum[j]+=a[i][j];
				if(i==n){
					a[i][j]=sum[j];
					sum[j]=0;
				}

				sum1+=a[i][j];
				if(j==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}

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

	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int data[150][150] = { 0 };

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

		}
		for (int i = 0;i < n+1;i++) {
			for (int j = 0;j < n + 1;j++) {
				if (data[i][j] < 10) {
					cout << "    " << data[i][j];
				}
				else if (data[i][j] < 100) {
					cout << "   " << data[i][j];
				}
				else if (data[i][j] < 1000) {
					cout << "  " << data[i][j];
				}
			}
			cout << endl;
		}
		

	}
	return 0;

}

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

using namespace std;

int main(void){
	int n;
	int a,b;
	int hyo[10][10];
	while(1){
		cin >> n;
		if(n==0)break;
		for(b=0;b<=n;b++){
			for(a=0;a<=n;a++){
				hyo[a][b]=0;
			}
		}
		for(b=0;b<n;b++){
			for(a=0;a<n;a++){
				cin >> hyo[a][b];
				hyo[n][b]+=hyo[a][b];
			}
		}
		for(b=0;b<=n;b++){
			for(a=0;a<n;a++){
				hyo[b][n]+=hyo[b][a];
			}
		}
		for(b=0;b<=n;b++){
			for(a=0;a<=n;a++){
				cout << hyo[a][b] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	int n;
	int data[12][12];

	while( cin >> n && n != 0 ){
		for( int i = 0;i < n;i++ ){
			for( int j = 0;j < n;j++ ){
				cin >> data[i][j];
			}
		}

		int sum = 0;
		for( int i = 0;i < n;i++ ){
			sum = 0;
			for( int j = 0;j < n;j++ ){
				sum += data[i][j];
			}
			data[i][n] = sum;
		}
		for( int i = 0;i < n + 1;i++ ){
			sum = 0;
			for( int j = 0;j < n;j++ ){
				sum += data[j][i];
			}
			data[n][i] = sum;
		}

		for( int i = 0;i < n + 1;i++ ){
			for( int j = 0;j < n + 1;j++ ){
				cout.width( 5 );
				cout << data[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>

using namespace std;


int n;
int table[11][11];
int row_sum;
int col_sum;


int main()
{
	while (cin >> n)
	{
		if (n == 0) break;
		
		for (int i=0; i<n; i++)
		{
			row_sum = 0;
			for (int j=0; j<n; j++)
			{
				cin >> table[i][j];
				row_sum += table[i][j];
			}
			table[i][n] = row_sum;
		}
		
		for (int i=0; i<=n; i++)
		{
			col_sum = 0;
			for (int j=0; j<n; j++)
			{
				col_sum += table[j][i];
			}
			table[n][i] = col_sum;
		}
		
		for (int i=0; i<=n; i++)
		{
			for (int j=0; j<=n; j++)
			{
				printf("%5d", table[i][j]);
			}
			cout << endl;
		}
	}
	
	return 0;
}

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];
        }
        cout << endl;
    }
    return true;
}

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

    while(solve()) ;
    return 0;
}