import           Control.Applicative
import           Control.Monad
import           Data.List

printInts :: [Int] -> IO ()
printInts = putStrLn . intercalate " " . fmap show

sumAll :: [[Int]] -> Int
sumAll = sum . fmap sum

colSums :: [[Int]] -> [Int]
colSums = fmap sum . transpose

appendCol :: [[Int]] -> [[Int]]
appendCol xss = fmap f xss
  where
    f ys = ys ++ [sum ys]

main :: IO ()
main = do
    getLine
    xss <- fmap (fmap read . words) . lines <$> getContents :: IO [[Int]]
    let total = sumAll xss
    let lastRow = colSums xss ++ [total]
    let answer = appendCol xss ++ [lastRow]
    mapM_ printInts answer

