line = Array.new
linef = Array.new
loop do
  num = gets.to_i
  if num == 0
    break
  end
  num.times do |i|
    data = gets.chomp!.split(/\s/)
    data.size.times do |j|
      data[j] = data[j].to_i
    end
    cnt = 0
    data.each do |k|
      cnt = cnt + k
    end
    data.push(cnt)
    line[i] = data
  end
  (num + 1).times do |l|
    cnt = 0
    num.times do |m|
      cnt = cnt + line[m][l]
    end
    linef[l] = cnt
  end
  num.times do |m|
    (num + 1).times do |n|
      printf("%d\s",line[m][n])
    end
    print "\n"
  end
  (num + 1).times do |o|
    printf("%d\s",linef[o])
  end
  print "\n"
end