Your task is to develop a tiny little part of spreadsheet software.  Write a program which adds up columns and rows of given table as shown in the following figure:  
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

n=int(input())
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)
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)