import Control.Applicative
import Data.List

getTableLines :: String -> [[Int]]
getTableLines tb = (map (map read) . map words . lines) tb

getTableRows :: String -> [[Int]]
getTableRows tb = (transpose . getTableLines) tb

getAnswer :: String -> String
getAnswer tb = (unlines . map unwords . map (map show)) (a ++ [b])
    where
        a = addLinesSum tb
            where
                addLinesSum :: String -> [[Int]]
                addLinesSum tb = [l ++ [sum l]| l <- (getTableLines tb)]
        b = getRowsSumAndTotal tb
            where
                getRowsSumAndTotal :: String -> [Int]
                getRowsSumAndTotal tb = [sum r | r <- rs] ++ [sum $ map sum rs]
                    where
                        rs = getTableRows tb
                

main :: IO ()
main = do
    _ <- getLine
    putStr =<< getAnswer <$> getContents