myread :: String->[[Int]]
myread = map (map (read::String->Int).words).tail.lines

rowsum :: [Int]->[Int]
rowsum = (\xs->xs++[sum xs])

colsum :: [[Int]]->[[Int]]
colsum [x] = [x]
colsum (x:y:xs) = colsum $ (zipWith (+) x y) : xs  

colsum2 :: [[Int]]->[[Int]]
colsum2 xs = xs ++ (colsum xs)

myprint :: [[Int]]->IO ()
myprint = mapM_ $ putStrLn.unwords.(map show)

main=getContents >>= myprint.colsum2.map rowsum.myread