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
}

Python: # Aizu Problem 0102: Matrix-like Computation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    N = int(input())
    if N == 0:
        break
    M = [[int(_) for _ in input().split()] for __ in range(N)]
    for i in range(N):
        M[i].append(sum(M[i]))
    last = [sum([M[row][col] for row in range(N)]) for col in range(N + 1)]
    M.append(last)
    fmt = "%5d" * (N + 1)
    for row in M:
        print(fmt % tuple(row))

Python: def print_list_inline(tr_list):
    inline = map(lambda string:"{:>5}".format(string),tr_list)
    inline = list(inline)
    print(("").join(inline))


while True:
    n = int(input())
    if n != 0:
        sum_col = [0 for i in range(n+1)]
        for i in range(n):
            list_row = list(map(int,input().split(" ")))
            sum_row = sum(list_row)
            list_row.append(sum_row)
            for j in range(len(list_row)):
                sum_col[j] += list_row[j]
            print_list_inline(list_row)
        print_list_inline(sum_col)
    else:
        break

Python: while 1:
 n=int(input())
 if n==0:break;
 a=[]
 for _ in[0]*n:
  b=list(map(int,input().split()))
  b+=[sum(b)]
  a+=[b]
  for s in b:print("%5d"%s,end='')
  print()
 for c in zip(*a):print("%5d"%sum(c),end='')
 print()

Python: import sys
f=lambda v,b: v.append(sum(b))
while True:
    c=input()
    if c==0: break
    x=range(c)
    z=range(c+1)
    q={}
    for i in x:
        q[i]=map(int,raw_input().split())
        t=q.values()[i]
        f(t,t)
    q[i+1]=[]
    for g in x:
        w=[]
        for j in x:
            w.append(q.values()[j][g]) 
        f(q[i+1],w)
    t=q[i+1]
    f(t,t)
    for i in q.values():
        for j in z:
            sys.stdout.write("%5d"%i[j])
        print

Python: while True:
    n = int(input())
    if n == 0:
        break

    a = []
    for i in range(n):
        a.append([int(num) for num in input().split()])

    for i in range(n):
        sum = 0
        for j in range(n):
            sum += a[i][j]
        a[i].append(sum)


    a.append([])
    for i in range(n + 1):
        sum = 0
        for j in range(n):
            sum += a[j][i]
        a[n].append(sum)

    for i in range(n + 1):
        for j in range(n + 1):
            print('{0:>5}'.format(a[i][j]), end="")
        print()

Python: from sys import stdin

if __name__ == '__main__':
    is_begin = False
    for n in stdin:
        if int(n) == 0:
            break
        else:
            if is_begin:
                print()
        is_begin = True

        bottom_total = []
        right_total = []
        for _ in range(int(n)):
            line = input().split(' ')
            total = 0
            for i, v in enumerate(line):
                print(repr(int(v)).rjust(5), end='')
                total += int(v)
                if len(bottom_total) < i + 1:
                    bottom_total.append(int(v))
                else:
                    bottom_total[i] += int(v)
            right_total.append(total)
            print(repr(right_total[_]).rjust(5))

        for num in bottom_total:
            print(repr(num).rjust(5), end='')
        print(repr(sum(bottom_total)).rjust(5), end='')

Python: while True:
	n = int(input())
	if n == 0: break
	arr = [[0 for r in range(n+2)] for c in range(n+2)]

	for r in range(n):
		arr[r] = list(map(int, input().split()))
		arr[r].append(sum(arr[r]))

	for c in range(n+1):
		s = 0
		for r in range(n): s += arr[r][c]
		arr[n][c] = s

	for r in range(n+1):
		for c in range(n+1): print(format(arr[r][c], '5d'), end='')
		print()

Python: while True:
    rows = []
    total = {}
    n = int(input())
    if (n == 0):
        break

    for r in range(n):
        datas = map(int, input().split())
        ds = list(datas)
        rows.append(ds)
            
    for r in range(n):
        s = 0
        for c in range(n):
            s += rows[r][c]
            if (c not in total):
                total[c] = rows[r][c]
            else:
                total[c] += rows[r][c]

        rows[r].append(s)
        if (n not in total):
            total[n] = s
        else:
            total[n] += s

    for r in range(n):
        for c in range(len(rows[r])):
            print("{0:>5}".format(rows[r][c]), end="")
        print()

    for t in range(len(total)):
        print("{0:>5}".format(total[t]), end="")
    print()

Python: import numpy

Python: import sys
import math

while True:
	n = int(input())
	if n == 0:
		break
	data = [list(map(int,input().split())) for i in range(n)]
	data.append([0 for i in range(n+1)])

	for i in range(n+1):
		if i != n:
			data[i].append(sum(data[i]))
		for j in range(n):
			data[n][i] = data[n][i]+data[j][i]
	for i in range(n+1):
		for j in range(n+1):
			if j != n:
				string = str('{:>5}'.format(data[i][j]))
				sys.stdout.write(string)
			else:
				print('{:>5}'.format(data[i][j]))

Python: while True:
    n = int(input())
    if n != 0:
        sum_col = [0 for i in range(n+1)]
        for i in range(n):
            list_row = list(map(int,input().split(" ")))
            sum_row = sum(list_row)
            list_row.append(sum_row)
            for j in range(len(list_row)):
                sum_col[j] += list_row[j]


            print("{:<10}".format("%s")%((" ").join(list(map(str,list_row)))))
        print("{:<10}".format("%s") % ((" ").join(list(map(str, sum_col)))))
    else:
        break

Python: def rowSum(matrix):
  n=len(matrix)
  sumcolumn=[0]*n
  for i in range(0,n):
    sumcolumn[i] = sum(matrix[i])
  return sumcolumn

def colSum(matrix):
  n=len(matrix)
  sumrow=[0]*n
  for i in range(0,n):
    for j in range(0,n):
      sumrow[i]+=matrix[j][i]
  return sumrow

while True:
  n=int(input())
  if n==0:  break
  matrix=[None]*n
  for i in range(0,n):
    matrix[i] = list(map(int,input().split()))

  c=rowSum(matrix)
  r=colSum(matrix)

  matrix.append(r)

  for i in range(0,n):
    matrix[i].append(c[i])

  matrix[n].append(sum(matrix[n]))

  for row in matrix:
    line=""
    for element in row:
      line += '{:>5}'.format(str(element))
    line.rstrip()
    print(line)

Python: while True:
    n = int(input())
    if n == 0:
        break
    rows = [list(map(int, input().split())) for _ in range(n)]
    for row in rows:
        for r in row:
            print("{:5d} ".format(r), end="")
        print("{:5d}".format(sum(row)))
    columns = list(zip(*rows))
    for column in columns:
        print("{:5d} ".format(sum(column)), end="")
    print("{:5d}".format(sum(sum(row) for row in rows)))