N,H,M,T = map(int,input().split()) if N == 1 : print(H) print(M) else : NN = (N - 1) * T NNN = NN//60 print(H + NNN) print(M + NN - 60 * NNN)