n,h,m,t = map(int,input().split()) late_time = (n-1)*t m +=late_time v1,v2 = divmod(m,60) print(h+v1,v2)