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

solve :: [[Int]] -> String
solve (rc:cs) =
    let matrix = transpose $ map attachSumCell $ transpose $ map attachSumCell cs in
    unlines [unwords [show c | c<-y] | y<-matrix]
    where
    attachSumCell :: [Int] -> [Int]
    attachSumCell c = c ++ [sum c]

main =
    putStr =<< solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = map (map read . words)