import Data.List

addSum :: [Int] -> [Int]
addSum list = list ++ [(sum list)]

main = do{
    n <- getLine;
    getContents >>= mapM_ putStrLn . map (unwords . map show) . transpose . map addSum . transpose . map ( addSum . map (read::String->Int)) . map words . lines;
}