r, c = gets.split.map(&:to_i)
arrs = []
sum_arr = Array.new(c, 0)
ARGF.each_line do |line|
  arrs << line.split.map(&:to_i)
end

arrs.each do |arr|
  print arr.join("\s")
  print "\s"
  puts  arr.inject(:+)
  c.times do |i|
    sum_arr[i] += arr[i]
  end
end

print sum_arr.join("\s")
print "\s"
puts  sum_arr.inject(:+)