a,b,c,d=[int(i) for i in input().split()] hun=(a-1)*d+c print((b+hun//60)%24) print(hun%60)