module Main where
--import Debug.Trace
import Data.List
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: Int -> [[Int]] -> [String]
solve cols = iterR (replicate cols 0) where
    iterR s []     = [edit s]
    iterR s (r:rs) = (edit r): iterR (sumCol s r) rs where
        sumCol [] [] = []
        sumCol (x:xs) (y:ys) = (x + y):sumCol xs ys
    edit l = concat (map (\x -> show x ++ " ") l) ++ show (sum l)

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

readLines :: Int -> IO [[Int]]
readLines 0 = return []
readLines n = readLine >>= (\a -> fmap (a:) (readLines (pred n)))

main :: IO() 
main = do
    [r, c] <- readLine
    l <- readLines r
    mapM_ putStrLn (solve c l)

