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 |n|
    (num + 1).times do |o|
      if (num + 1) == (o + 1)
        printf("%d\n",line[n][o])
      else
        printf("%d\s",line[n][o])
      end
    end
  end
  (num + 1).times do |p|
    if (num + 1) == (p + 1)
      printf("%d\n",linef[p])
    else
      printf("%d\s",linef[p])
    end
  end
end