#coding:utf-8 N,H,M,T=map(int,raw_input().split()) N-=1 while N: M+=T if M==60: M=0 H+=1 N-=1 print H print M