N, H, M, T = map(int,input().split(' ')) A = M + T * (N - 1) if A < 60: print(H) print(A) else: H = H + A // 60 A = A % 60 print(H) print(A)