gets

total=[]

while line = gets
  arr = line.chomp.split(/\s+/).map(&:to_i)
  puts "#{arr.join(" ")} #{arr.sum}"
  arr.each_with_index {|v,i| total[i] ||=0; total[i] += v}
end
puts "#{total.join(" ")} #{total.sum}"
