datasets = []

while true
  n = gets.to_i
  break if n <= 0
  data = [] 
  n.times do
    data << gets.chomp!.split.map(&:to_i)
  end
  datasets << data
end

datasets.each do |data|
  r_sum, c_sum = [], []
  
  data.each do |row|
    r_sum << row.inject(0) {|s, x| s + x}
  end
  data.transpose.each do |col|
    c_sum << col.inject(0) {|s, x| s + x}
  end

  data.each_with_index do |row, i|
    row.each {|n| print "#{n} "}
    puts r_sum[i]
  end

  c_sum.each {|n| print  "#{n} "}
  puts c_sum.inject(0) {|s, x| s + x}
end