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