import Control.Monad
import Control.Applicative

vertSum table = [sum [row !! i | row <- table] | i <- [0..(length (head table) - 1)]]

processSheet table = rowWithTot ++ [newRow]
    where rowWithTot = map (\row -> row ++ [sum row]) table
          newRow = vertSum rowWithTot

myPrint = mapM_ (putStrLn . unwords . map show)

main = do
    _ <- getLine
    myPrint . processSheet =<< map (map (read :: String->Int) . words) <$> lines <$> getContents