a, b, c, d = map(int, input().split()) delta = (a-1)*d num = 60 * b + c num += delta num %= (60*24) p = num//60 num%=60 print(p) print(num)