# 1 ? r, c ? 100
# (r + 1) × (c + 1) 

require 'matrix'

r, c = gets.split.map(&:to_i)
ary = []

ARGF.each do |line|
  ary << line.split.map(&:to_i)
end

# puts Matrix[ary]
# column 列ベクトル

# puts Matrix[ary]


c.times do |col|
  col = 0
  Matrix[ary].column(col).to_a[0].each do |a|
    i += a
  end
  puts col
end

r.times do |row|
  i = 0
  Matrix[ary].column(row).to_a[0].each do |b|
    row += b
  end
  puts row
end