N, H, M, T = map(int, input().split()) d, m = divmod(M + (N - 1) * T, 60) print(H+d) print(m)