import Control.Applicative

main = do _ <- getLine
          xs <- map (map read . words) . lines <$> getContents
          putStr . unlines . map (unwords . map show) . addRow $ map sumRow xs

sumRow :: [Int] -> [Int]
sumRow x = x ++ ((sum x):[])

addRow :: [[Int]] -> [[Int]]
addRow xs = xs ++ (makeRow xs:[])

makeRow :: [[Int]] -> [Int]
makeRow (x:_) | x==[] = []
makeRow xs = (sum $ map head xs) : makeRow (map tail xs)

sample :: [[Int]]
sample = [[1,1,3,4,5],[2,2,2,4,5],[3,3,0,1,1],[2,3,4,4,6]]