{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Array.IO
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf
import Debug.Trace


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = do
    [r, c] <- replicateM 2 readInt
    s <- newArray (1,c) 0 :: IO (IOUArray Int Int)
    forM_ [1..r] $ \_ ->
        let g n | n == c + 1 = return 0
                | otherwise = do
                    x <- readInt
                    putStr $ show x ++ " "
                    writeArray s n . (+x) =<< (readArray s n)
                    (+x) <$> g (n+1)
        in print =<< g 1
    let g n | n == c + 1 = return 0
            | otherwise = do
                t <- readArray s n
                putStr $ show t ++ " "
                (+t) <$> g (n+1)
        in print =<< g 1
