N,H,M,T = map(int, input().split()) import math def weakup_time(N,H,M,T): loss_time = T*(N-1) H=60*H time = H+M+loss_time time = time-24*60*math.floor(time/(24*60)) print(math.floor(time/60)) print(time-60*math.floor(time/60)) weakup_time(N,H,M,T)