import Control.Applicative
import Control.Monad

solve :: Int -> [[Int]] -> [[Int]]
solve c table = rows ++ [row]
    where
        rows = map (\r -> r ++ [foldl (+) 0 r]) table
        row  = map (\i -> foldl (\a r -> a + (r !! i)) 0 rows) [0 .. c]

main :: IO ()
main = do
    [r, c] <- map read . words <$> getLine
    table  <- map (map read . words) <$> replicateM r getLine
    putStr $ unlines $ map (unwords . map show) $ solve c table