import Data.Functor ((<$>))
import Data.List (transpose)

main :: IO ()
main = do
    sheet <- map (map read . words) . tail . lines <$> getContents :: IO [[Int]]
    let sheet' = sumRow $ sumCol sheet
    putStrLn . unlines . map (unwords . map show) $ sheet'
  where sumRow = map (\r -> r ++ [sum r])
        sumCol = transpose . sumRow . transpose

