N,H,M,T = map(int, raw_input().split()) minute = 60 * H + M + T * ( N - 1 ) print ( minute / 60 ) % 24 print minute % 60