if true then
  fh=STDIN
else
  fh=open("in0102.txt")
end
while true
  n=fh.gets.to_i
  break  if n ==0
  g=[]
  m=0

  0.upto(n-1){|i|
    f = fh.gets.chomp.split.map{|x| x.to_i}
    m=f.length if m==0
    f.push(f.inject(0){|acc,x|acc+x})
    g.push(f)
  }

  gs=[]
  0.upto(m){|j|
    gs[j]=0
    0.upto(g.length-1){|i|
      gs[j] += g[i][j]
    }
  }
  g.push gs

  g.each{|v|
    puts v.map{|x| sprintf("%5d", x)}.join
  }

end