module Main where import Control.Monad main :: IO () main = do [n, h, m, t] <- fmap read . words <$> getLine :: IO [Int] let minutes = h * 60 + m + (n - 1) * t let (hh, mm) = (minutes `mod` 1440) `divMod` 60 print hh print mm