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