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