r,c=gets.split.map(&:to_i)
seet=[]
r.times do
    seet.push(gets.split.map(&:to_i))
end
2.times do 
    seet.each do |s|
        s.push(s.inject{|a,b|a+b})
    end
    seet=seet.transpose
end
seet.each do |nums|
    puts nums.join(" ")
end

