type Row  = [Int]
type Matrix = [Row]

main = getContents >>= putOut.formatOut.solve.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
  
formatIn :: String -> Matrix
formatIn =  map ((map (read :: String -> Int)).words).tail.lines

formatOut :: Matrix -> String
formatOut = unlines.map (unwords.(map show)) 

solve :: Matrix -> Matrix
solve rows = newRow ++ [allSum (newRow++[])]
  where addSum xs = xs ++ [sum xs]
        newRow = map addSum rows
        allSum [] = [0,0..]
        allSum (y:ys) = zipWith (+) y $allSum ys