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