N, H, M, T = map(int, input().split()) h = H m = (N - 1) * T + M if m >= 60: h_a = m // 60 m = m - (h_a * 60) h = H + h_a print(h) print(m)