while n = gets.to_i
  break if n == 0
  m = []
  t = Array.new(n+1,0)

  n.times{
    a = gets.split(/ /).map(&:to_i).push(0)
    m.push(a)
    n.times{|i| t[i]+=a[i] }
  }

  m.push(t)

  (0..n).each{|i| m[i][n]=m[i].inject(:+)}

  m.each{|r| r.each{|c| print "%05s"%(c)};puts}
end