import Control.Applicative ((<$>))
import qualified Control.Monad as Monad (forM, replicateM)

type Row = [Int]
type Spreadsheet = [Row]

main = do
    [r,c] <- getLine'
    xs <- Monad.replicateM r $ getLine'
    mapM_ (putStrLn . printFormat) =<< newSpreadsheet (c+1) xs

getLine' :: IO [Int]
getLine' = map read . words <$> getLine

printFormat :: Row -> String
printFormat xs = unwords $ show <$> xs

newSpreadsheet :: Int -> Spreadsheet -> IO Spreadsheet
newSpreadsheet n xs = do
    let xs' = zipWith (++) xs $ rowSums xs
    return $ xs' ++ columnSums n xs'

rowSums :: Spreadsheet -> Spreadsheet
rowSums = map $ (:[]) . sum

columnSums :: (Monad m) =>Int -> Spreadsheet -> m Row
columnSums n xs = Monad.forM [0..(n-1)] $ \i -> return $ sum $ map (!! i) xs