while true
  n, arr = gets.to_i, []
  
  break if n == 0
  
  n.times do |i|
    arr[i] = gets.split.map(&:to_i)
    
    arr[i][n] = 0
    
    n.times do |j|
      arr[i][n] += arr[i][j]
    end
  end
  
  arr[n] = Array.new(n + 1, 0)
  
  (n + 1).times do |i|
    n.times do |j|
      arr[n][i] += arr[j][i]
    end
    
    puts arr[i].join(" ")
  end
end