until (n = gets.to_i).zero?
  arr = Array.new(n + 1, Array.new(n + 1, 0))
  
  n.times do |i|
    arr[i] = gets.split.map(&:to_i).push(0)
    
    n.times do |j|
      arr[i][n] += arr[i][j]
    end
  end
  
  (n + 1).times do |i|
    (n + 1).times do |j|
      arr[n][i] += arr[j][i] unless j == n
    end
    
    puts "%5d" * (n + 1) % arr[i]
  end
end