n, h, m, t = map(int, input().split()) d = 1440 wu = (60 * h + m + (n-1) * t)%d w, m = divmod(wu, 60) print(w) print(m)