solve xss
    | all null xss = []
    | otherwise = (sum $ map head xss) : (solve $ map tail xss)


main = do
    _ <- getLine
    str <- getContents
    let xs = zipWith ($) (repeat $ (map read) . words) (lines str) :: [[Int]]
    let xs' = map (\x -> x ++ [sum x]) xs
    putStrLn $ unlines $ map (unwords . (map show)) (xs' ++ [solve xs'])