N,H,M,T = map(int,input().split()) time = (N-1)*T a,b = divmod((M+time),60) print(H+a) print(b)