import Control.Applicative
import Control.Monad
import Data.List

addList::[Int]->[Int]->[Int]
addList [x] [y] = [ x + y ]
addList x [] = x
addList [] y = y
addList (x:xs) (y:ys) = [x + y] ++ addList xs ys

main = do
    r:_ <- map read.words <$> getLine
    ss <- replicateM r (map read.words <$> getLine) ::IO[[Int]]
    let a = [ s ++ [sum s] | s <- ss]
    let b = foldr addList [] a
    putStrLn $ ((intercalate "\n"). map(unwords.map show)) a
    putStrLn $ (unwords.map show) b
    