N, H, M, T = map(int, input().split()) sum_T = (N - 1) * T #起きるまでのp時間 mtoh = M + sum_T if mtoh >= 60: hour = mtoh // 60 H = H + hour minute = mtoh % 60 M =0 M = minute print(H) print(M) elif mtoh < 60: minute = M + mtoh print(H) print(mtoh)