N, H, M, T = map(int, input().split()) losstime = (N - 1) * T H += (losstime + M) // 60 M = (losstime + M) % 60 print(H) print(M)