import Control.Monad
import Control.Applicative
import Data.List
main = do
  [n,m]<-map (read::String->Int) . words <$> getLine
  rows <-  map (map (read::String->Int) .words) <$> (replicateM n getLine)
  putStr $ unlines $ map (unwords . map show) $ extendR $ extendC rows

extendC:: Num a => [[a]]->[[a]]
extendC = map (\r-> r ++ [sum r])


extendR:: Num a => [[a]]->[[a]]
extendR mat = mat ++ [(foldl1 (zipWith (+)) mat)]