n,h,m,t = map(int,input().split()) v = h*60 + m + (n-1)*t print(v//60) print(v%60)