list1 =list(map(int, input().split())) N = list1[0] H = list1[1] M = list1[2] T = list1[3] A = (N-1)*5 print(H + (A+M) // 60) print(A + M - (A + M // 60))