#Sleep N times 296 N,H,M,T=(int(i) for i in input().split()) N-=1 N*=T M+=N H1=M//60 H+=H1 M%=60 H%=24 print(H) print(M)