N, H, M, T = (map(int, input().split())) at = H *60 + M + (N-1)*T A = at//60 B = at%60 print(A) print(B)