while 0 != n = gets.to_i do
  a = Array.new(10,0)
  n.times do
    print s = gets.chomp
    s = s.split.map(&:to_i)
    d = 0
    n.times do |i|
      d = d + s[i]
      a[i] = a[i] + s[i]
    end
    puts " #{d}"
  end
  z = 0
  n.times do |i|
    z = z + a[i]
    print "#{a[i]} "
  end
  puts z
end