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