import Control.Monad
import Data.List

getList :: Read a => IO [a]
getList = fmap (map read . words) getLine

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

main :: IO ()
main = do
  [r, c] <- getList
  inputs <- replicateM r getList
  mapM_ putStrLn $ map (unwords . map show . addSum) inputs
  let inputst = transpose inputs
  putStrLn $ unwords $ map show $ addSum $ map sum $ inputst