while 0 != n = gets.to_i do
  a = Array.new(10,0)
  n.times do
    s = gets.split.map(&:to_i)
    d = 0
    n.times do |i|
      printf("%5d",s[i])
      d = d + s[i]
      a[i] = a[i] + s[i]
    end
    printf("%5d\n",d)
  end
  z = 0
  n.times do |i|
    z = z + a[i]
    printf("%5d",a[i])
  end
  printf("%5d\n",z)
end