N,H,M,T = list(map(int, input().split())) if N > 1: M += (N-1) * T else: M += N * T if M > 60: h += 1 m -= 60 print (H) print (M)