--Structured Program II - Spreadsheet

import Control.Applicative
import Data.List (transpose)

main :: IO ()
main = do
  [r, _] <- map read . words <$> getLine
  xs <- take r . map (map read . words) . lines <$> getContents
  mapM_ (putStrLn . unwords . map show) $ spreadSheet xs

spreadSheet :: [[Int]] -> [[Int]]
spreadSheet xs = (f . f) xs
  where f xs = map (\x -> x ++ [sum x]) $ transpose xs

