import Control.Applicative

type Sheet = [[Int]]

type Problem = (Int, Sheet)

type Result = Sheet

solve :: Problem -> Result

solve (cols, sheet)
    = nrows ++ [lower] where
        nrows = [row ++ [sum row] | row <- sheet]
        lower = [sum [row !! col | row <- nrows] | col <- [0..cols]]

output :: Result -> String

output sheet
    = init.concat $ [(init.concat $ [show x ++ " " | x <- row]) ++ "\n" | row <- sheet]
    
input :: IO Problem

input
    = do
        [rows, cols] <- map read.words <$> getLine
        sheet <- inputSheet rows []
        return (cols, sheet)
        
inputSheet :: Int -> Sheet -> IO Sheet

inputSheet 0 sheet
    = return sheet
    
inputSheet rows sheet
    = do
        row <- map read.words <$> getLine
        inputSheet (rows - 1) $ sheet ++ [row]
    
main :: IO ()

main
    = putStrLn.output =<< solve <$> input