import Data.List

main = interact $ show' . solve . read' . lines
  where
    solve = addCol . addRow
    addCol xs = map appendSum xs
    addRow = transpose . addCol . transpose
    appendSum row = row ++ [sum row]
    show' = unlines . map (unwords . map show)
    read' = map (map read . words) . tail :: [String] -> [[Int]]

