while (n=gets.to_i)!=0
  mat=Array.new(n+1){Array.new(n+1,0)}
  ans=Array.new(n+1){Array.new(n+1)}
  n.times.with_index do |id|
    mat[id]=gets.split.map(&:to_i)
    mat[id][n]=mat[id].inject(:+)
    (n+1).times.with_index do |id2|
      mat[n][id2]+=mat[id][id2]
    end
  end
  mat.each.with_index do |item,id|
    item.each.with_index do |ss,id2|
      ans[id][id2]=format("%5d",ss)
    end
  end
  ans.each do |line|
    puts line.join
  end
end