module Main where

import Control.Applicative
import Numeric
import Data.List (transpose)


main :: IO ()
main = do
  {[r, c] <- getInts
  ; mat <- loop r
  ; mapM_ putInts (hoge mat)
  }

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

hoge :: [[Int]] -> [[Int]]
hoge = transpose . map addSum. transpose . map addSum

addSum  :: [Int] -> [Int]
addSum xs = xs ++ [sum xs]
  
--
getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words  <$> getLine

putDoubles :: [Double] -> IO()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""
