import Control.Monad
import Data.List

sumAdd :: [Int] -> [Int]
sumAdd x = x ++ [sum x]

solv :: [[Int]] -> [[Int]]
solv l = transpose . map sumAdd . transpose . map sumAdd $ l

showRes :: [[Int]] -> String
showRes [] = ""
showRes (x:xs) = (concat . intersperse " " . map show $ x) ++ "\n" ++ (showRes xs)

main = getLine >>=
       (\l -> return (map read . words $ l)) >>=
       (\(r:c:_) -> replicateM r getLine) >>=
       (\l -> return (map (map read . words) $ l :: [[Int]] )) >>=
       (\a -> return (solv a)) >>=
       putStr . showRes