{-# LANGUAGE BangPatterns #-} {-# LANGUAGE TypeApplications #-} import Control.Applicative ((<$>)) import Data.Char (isSpace) import Data.List (unfoldr) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B getL :: (ByteString -> [Int]) -> IO [Int] getL f = f <$> B.getLine readIL :: (ByteString -> Maybe (Int, ByteString)) -> (ByteString -> [Int]) readIL f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') main :: IO () main = putStr =<< unlines . solve <$> getL (readIL B.readInt) solve :: [Int] -> [String] solve [n, h, m, t] = [x, y] where p = (n - 1) * t + m (a, b) = p `divMod` 60 c = (a + h) `mod` 24 x = show c y = show b