N,H,M,T = map(int,input().split()) if N != 1: full_M = ((H * 60 + M) + (N - 1) * T) print(full_M // 60) print(full_M % 60) else: print(H) print(M)