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