n, h, m, t = io.read("*n", "*n", "*n", "*n") m = m + (n - 1) * t a = math.floor(m / 60) h, m = (h + a) % 24, m - a * 60 print(h) print(m)