a, b, c, d = map(int,input().split()) e = (60*b+c+d*(a-1))%1440 f = e//60 g = (e-60*f) print(f) print(g)