import Data.List
main = do
  s <- getLine 
  let [r,c] = map (read::(String->Int)) . words $ s
  ss <-getContents
  let v = map (map read . words) . lines $ ss :: [[Int]]
  mapM_ putStrLn (map (intercalate " " . map show) $ calc v)

calc :: [[Int]] -> [[Int]]
calc v = (zipWith (++) v (transpose [hsum])) ++ [(vsum ++ [sum vsum])]
  where hsum = map sum v
        vsum = map sum $ transpose v