N,H,M,T=map(int,input().split()) s=(N-1)*T+M H+=s//60 s%=60 print(str(H%24)+"\n"+str(s))