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