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