module Main where

import Data.Functor
import Data.List

main :: IO ()
main =  do
 { [r,c] <- getInts
 ; sheet <- loop r
 ; putStr $ unlines $ map (unwords . map show) $ transpose $ map addsum $ transpose sheet
 }

loop :: Int -> IO [[Int]]
loop 0 = return []
loop n = do
  { r <- getInts
  ; rs <- loop (n-1)
  ; return (addsum r : rs)
  }

addsum :: [Int] -> [Int]
addsum xs = xs ++ [sum xs]

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