#!/usr/bin/env ruby

numbers = gets.split.map(&:to_i)
WIDTH = numbers[1]
HEIGHT = numbers[0]
result = []

(WIDTH-1).times do 
    temp = 0
    row = gets.split.map(&:to_i)
    row.each do |value|
        temp += value
        result << value
    end
    result << temp
    row.clear
end

(WIDTH+1).times do |index|
    temp = 0
    HEIGHT.times do |rownumber|
        temp += result[(rownumber*(WIDTH+1)) + index]
    end
    result << temp
end

result.count.times do |i|
    print result[i]
    if i % (WIDTH+1.0) == WIDTH then
        puts ""
    else 
        print " "
    end
end
