import Control.Monad
main = do
  rc_in <- (return . map (read::String->Int) . words) =<< getLine
  let r:c:[] = rc_in
  v <- replicateM r $ (return . map (read::String->Int) . words) =<< getLine
  let v1 = [i ++ [sum i]|i<-v]
  let v2 = v1 ++ [[(sum [j!!i | j<-v1]) |i<-[0..c]]]
  forM_ [0..r] $ \i -> do
    forM_ [0..c] $ \j -> do
      putStr $ show ((v2!!i)!!j)
      putStr $ if j == c then "\n" else " "
